Skip to content

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Jun 30, 2024

Fixes #185

The current autofix for the terraform_deprecated_interpolation rule does not recognize expression context and will always fix "${var.foo}" to var.foo. However, if an object key is a deprecated interpolation, it must be wrapped in parentheses to prevent ambiguous attribute key errors.

This PR takes inspiration from hashicorp/terraform#26949 and fixes it so that autofixed code are wrapped in parentheses when the object key is a deprecated interpolation.

Before

locals {
  tags = {
    var.foo = "bar" # => ambiguous attribute key
  }
}

After

locals {
  tags = {
    (var.foo) = "bar"
  }
}

@wata727 wata727 merged commit 728b2fa into main Jul 6, 2024
@wata727 wata727 deleted the fix_ambiguous_keys_autofix branch July 6, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Autofix for the deprecated interpolation rule produces ambiguous attribute keys
1 participant