-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrades to work with Terraform v0.12.20 #12
Conversation
Run `terraform 0.12upgrade` against codebase. Note that due to Terraform 0.12 now using sets, we call `tolist` to workaround [1] [1] hashicorp/terraform-provider-aws#7522
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @Gowiem for contrubution!
This repo is in our queue to convert to TF 0.12. It is not enough to just replace syntax but we have requirements to cover module with tests. If you want to contribute it in a proper way (see example) you are most welcome! Give it a try, then ping me, so I could review and run tests. This will help us and speed up the process. Otherwise we all have to wait until it will be done as well as many other modules in queue
@maximmi I'm giving this a shot as I'd like to give back to you folks for these awesome modules (even if this one is one of the simplest out there), but I didn't get too far. Honestly, I think my lack of Make + Go knowledge make this an uphill battle, but I'm happy to bang at it if you or @osterman are willing to provide some guidance. 😅 Current status, is that the example works when running locally, but I'm unable to get very far due to the following:
The above led me to running the following and I got the following errors:
Stopped there as something seems off. Is it possibly trying to lint / validate using v0.11 Terraform instead of v0.12?
Anyway, I'm stopping here as I'm a little out of my depth on your folks setup, but if it seems I'm just missing some key steps then please point me in a direction and I'll work to give it another shot. Thanks folks! |
@Gowiem this is your PR/hard work so i'm just going to share some learnings... batsaside from ensuring bats was installed, i:
# main.tf
terraform {
required_version = "~> 0.12"
required_providers {
aws = "~> 2.58"
}
}
provider "aws" {
region = var.region
}
# variables.tf
variable "region" {
type = string
description = "AWS region to target"
default = ""
}
that got bats happy: ➜ make all
Running tests in ../
1..10
ok 1 check if terraform is installed
ok 2 check if terraform code needs formatting
ok 3 check if terraform modules are valid
ok 4 check if terraform modules are properly pinned
ok 5 check if terraform plugins are valid
ok 6 check if terraform providers are properly pinned
ok 7 check if terraform code is valid
ok 8 check if terraform-docs is installed
ok 9 check if terraform inputs have descriptions
ok 10 check if terraform outputs have descriptions
Running tests in ../examples/complete
1..5
ok 1 check if terraform is installed
ok 2 check if terraform code needs formatting
ok 3 check if terraform modules are valid
ok 4 check if terraform plugins are valid
ok 5 check if terraform code is valid terratestfrom the looks of the Makefile it's intended to run in an Alpine Dockerfile in a CI/CD pipeline,
# examples/complete/main.tf
module "store" {
source = "../../"
region = "us-east-1" # added
then it was all go test related, you gave me a good start. here's what i ended up with: package test
import (
"strings"
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)
// Test the Terraform module in examples/complete using Terratest.
func TestExamplesComplete(t *testing.T) {
t.Parallel()
terraformOptions := &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: "../../examples/complete",
Upgrade: true,
}
// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer terraform.Destroy(t, terraformOptions)
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
// Run `terraform output` to get the value of an output variable
output := terraform.Output(t, terraformOptions, "map")
result := strings.Contains(output, "Amazon")
// Verify we're getting back the outputs we expect
assert.Equal(t, true, result)
} that got terratest happy: --- PASS: TestExamplesComplete (57.94s)
PASS
ok terraform-aws-ssm-parameter-store 59.188s observationthis was a fun learning experience, and i'm not sure how far we should stray from the intent of the PR with this update... i do have some concern over putting passwords/secrets (even examples) in source control. it might be worth another PR to re-work this (and anything like it) to inject secrets via the environment (12F/HashiCorp best practice). hth, let me know if you have any questions! |
well if you guys are doing all this, then I guess I should try to add the KMS + s3 options too, if you are ok with that @Gowiem |
Do we even need this conditional? Why was this linux specific exactly?
@maximmi This should be ready for 👀 . I got everything running locally and all bats + terratests pass. @deadlysyn Thanks for the pointers! Some of them definitely helped, but I also had some weird environment issues going on which were holding me back. Primarily:
As part of trying to get this working I ran into some other issues with the CP build-harness and test-harness. Put up PRs for those issues:
Haha it has been a fun few hours 😅 @jamengual, not sure what you're referring to regarding KMS + S3 option (would love a link), but go for it! |
@Gowiem thank you for your contribution! Great job! I will take a look on this closely next week |
/codefresh run test |
Info
Following up on #10, this PR uses that fork and then applies the most recent requirement: Updates the
type
forparameter_write
variable so terraform can run without errors.