Skip to content

Commit

Permalink
Mock iam_endpoint explicitly for testing with localstack
Browse files Browse the repository at this point in the history
Starting from Terraform v1.6, the s3 backend configuration has changed,
and the tfmigrate acceptance test fails. I suspect that the
authentication mechanism may have been changed with the migration to
aws-sdk-go-v2; I have tried a few things and found that I can
authenticate by specifying the `iam_endpoint`. The `iam_endpoint`
argument has been deprecated since Terraformv1.6. It is recommended to
use the newly added `endpoints` argument, though, for running tests on
multiple Terraform versions, the test settings must remain compatible
with the older versions. This is a test-only issue, so I'll use the
deprecated `iam_endpoint` for now. In the future, we should change the
backend configuration depending on the Terraform version.
  • Loading branch information
minamijoyo committed Oct 5, 2023
1 parent 6f656f7 commit 7591205
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion test-fixtures/backend_s3/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ terraform {
bucket = "tfstate-test"
key = "test/terraform.tfstate"

# mock s3 endpoint with localstack
# mock s3/iam endpoint with localstack
endpoint = "http://localstack:4566"
iam_endpoint = "http://localstack:4566"
access_key = "dummy"
secret_key = "dummy"
skip_credentials_validation = true
Expand Down
3 changes: 2 additions & 1 deletion test-fixtures/storage_gcs/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ terraform {
bucket = "tfstate-test"
key = "test/terraform.tfstate"

# mock s3 endpoint with localstack
# mock s3/iam endpoint with localstack
endpoint = "http://localstack:4566"
iam_endpoint = "http://localstack:4566"
access_key = "dummy"
secret_key = "dummy"
skip_credentials_validation = true
Expand Down
3 changes: 2 additions & 1 deletion test-fixtures/storage_s3/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ terraform {
bucket = "tfstate-test"
key = "test/terraform.tfstate"

# mock s3 endpoint with localstack
# mock s3/iam endpoint with localstack
endpoint = "http://localstack:4566"
iam_endpoint = "http://localstack:4566"
access_key = "dummy"
secret_key = "dummy"
skip_credentials_validation = true
Expand Down
5 changes: 3 additions & 2 deletions tfexec/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,17 @@ terraform {
# bucket = "tfstate-test"
key = "%s/terraform.tfstate"
# mock s3 endpoint with localstack
# mock s3/iam endpoint with localstack
endpoint = "%s"
iam_endpoint = "%s"
access_key = "dummy"
secret_key = "dummy"
skip_credentials_validation = true
skip_metadata_api_check = true
force_path_style = true
}
}
`, t.Name(), endpoint)
`, t.Name(), endpoint, endpoint)
source := `
resource "null_resource" "foo" {}
resource "null_resource" "bar" {}
Expand Down
5 changes: 3 additions & 2 deletions tfexec/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,17 @@ terraform {
bucket = "%s"
key = "%s"
# mock s3 endpoint with localstack
# mock s3/iam endpoint with localstack
endpoint = "%s"
iam_endpoint = "%s"
access_key = "%s"
secret_key = "%s"
skip_credentials_validation = true
skip_metadata_api_check = true
force_path_style = true
}
}
`, TestS3Region, TestS3Bucket, key, endpoint, TestS3AccessKey, TestS3SecretKey)
`, TestS3Region, TestS3Bucket, key, endpoint, endpoint, TestS3AccessKey, TestS3SecretKey)
return backendConfig
}

Expand Down

0 comments on commit 7591205

Please sign in to comment.