terrafmt icon indicating copy to clipboard operation
terrafmt copied to clipboard

Format quoted string verb not supported inside Terraform configuration function definition

Open bflad opened this issue 5 years ago • 0 comments

Description

When using terrafmt diff -f with the following configuration snippet:

	return fmt.Sprintf(`
data "aws_caller_identity" "current" {}

resource "aws_signer_signing_profile" "test" {
  platform_id = "AWSLambda-SHA384-ECDSA"
  name        = replace(%[1]q, "-", "_")
}
# ...
`, rName)
}

An error is returned because the string is not quoted properly during format verb handling (note: replace(TFFMTKTBRACKETPERCENT[1]q, \"-\", \"_\")):

time="2020-11-24 18:23:42" level=error msg="block 1 @ ./aws/data_source_aws_signer_signing_job_test.go:34 failed to process with: failed to parse hcl: ./aws/data_source_aws_signer_signing_job_test.go:5,49-50: Missing argument separator; A comma is required to separate each function argument from the next.\ndata \"aws_caller_identity\" \"current\" {}\n\nresource \"aws_signer_signing_profile\" \"test\" {\n  platform_id = \"AWSLambda-SHA384-ECDSA\"\n  name        = replace(TFFMTKTBRACKETPERCENT[1]q, \"-\", \"_\")\n}\n\nresource \"aws_s3_bucket\" \"source\" {\n  bucket = \"%[1]s-source\"\n\n  versioning {\n    enabled = true\n  }\n\n  force_destroy = true\n}\n\nresource \"aws_s3_bucket\" \"destination\" {\n  bucket        = \"%[1]s-destination\"\n  force_destroy = true\n}\n\nresource \"aws_s3_bucket_object\" \"source\" {\n  bucket = aws_s3_bucket.source.bucket\n  key    = \"lambdatest.zip\"\n  source = \"test-fixtures/lambdatest.zip\"\n}\n\nresource \"aws_signer_signing_job\" \"test\" {\n  profile_name = aws_signer_signing_profile.test.name\n\n  source {\n    s3 {\n      bucket  = aws_s3_bucket_object.source.bucket\n      key     = aws_s3_bucket_object.source.key\n      version = aws_s3_bucket_object.source.version_id\n    }\n  }\n\n  destination {\n    s3 {\n      bucket = aws_s3_bucket.destination.bucket\n    }\n  }\n}\n\ndata \"aws_signer_signing_job\" \"test\" {\n  job_id = aws_signer_signing_job.test.job_id\n}\n"

bflad avatar Nov 24 '20 18:11 bflad