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

tflint incorrectly warns on interpolation-only map attributes (terraform_deprecated_interpolation) #1462

Closed
willhughes-au opened this issue Aug 1, 2022 · 2 comments

Comments

@willhughes-au
Copy link

Introduction

With a recent change, tflint now returns a Warning when I have an interpolation-only string attribute in a map.

Applying the suggestion results in invalid HCL that Terraform rejects.

Expected Behavior

It should not suggest/warn on interpolation-only string attributes in a map.

Actual behavior

Running tflint over the example playbook results in this warning:

Warning: Interpolation-only expressions are deprecated in Terraform v0.12.14 (terraform_deprecated_interpolation)

Step to Reproduce

Run this example against tflint 0.39.1:

locals {
        foo = "bar"
}

output "map_a" { 
    value = {
        "${local.foo}" : "baz"
    }
}

Additional Context

This is the (invalid) suggestion:

locals {
        foo = "bar"
}

output "map_b" { 
    value = {
        local.foo : "baz"
    }
}

Running this results in an error from Terraform:

$ tf plan
╷
│ Error: Ambiguous attribute key
│ 
│   on test.tf line 12, in output "map_b":
│   12:         local.foo : "baz"
│ 
│ If this expression is intended to be a reference, wrap it in parentheses. If it's instead intended as a literal name containing periods, wrap it in quotes to create a string literal.
$ tflint -v
TFLint version 0.39.1
$ terraform -v
Terraform v1.2.6
@willhughes-au
Copy link
Author

I think this may be related to #1257

@wata727 wata727 added the bug label Aug 1, 2022
@bendrucker bendrucker removed the bug label Aug 1, 2022
@bendrucker
Copy link
Member

What suggestion? The full output is as follows:

Warning: Interpolation-only expressions are deprecated in Terraform v0.12.14 (terraform_deprecated_interpolation)

  on main.tf line 7:
   7:         "${local.foo}" : "baz"

Reference: https://github.com/terraform-linters/tflint/blob/v0.39.1/docs/rules/terraform_deprecated_interpolation.md

This is indeed an unnecessary interpolation:

https://www.terraform.io/language/expressions/types#maps-objects

You can use a non-literal string expression as a key by wrapping it in parentheses

Terraform gives you this hint right in the error message.

A correctly formatted key expression (parentheses, not interpolation) will not raise warnings in TFLint, both on older versions, and the latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants