Skip to content

Autofix for the deprecated interpolation rule produces ambiguous attribute keys #185

@wata727

Description

@wata727

Follow up of #184

The terraform_deprecated_interpolation rule may produce ambiguous attribute keys if the map key contains a deprecated interpolation.

$ cat main.tf
variable "foo" {}

locals {
  tags = {
    "${var.foo}" = "bar"
  }
}
$ terraform validate
Success! The configuration is valid.

$ tflint --fix --only terraform_deprecated_interpolation
1 issue(s) found:

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

  on main.tf line 5:
   5:     "${var.foo}" = "bar"

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

$ cat main.tf
variable "foo" {}

locals {
  tags = {
    var.foo = "bar"
  }
}
$ terraform validate
terraform validate

│ Error: Ambiguous attribute key

│   on main.tf line 5, in locals:
│    5:     var.foo = "bar"

│ 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.

This is probably an autofix bug; it should produce (var.foo). Instead of always removing "${}", we should probably implement context-sensitive autofix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions