Skip to content

deprecated_interpolation: Prevent autofix from producing ambiguous attribute keys #189

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

Merged
merged 1 commit into from
Jul 6, 2024

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
2 checks passed
@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