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

Multiple format verbs in conditional not handled correctly #38

Closed
ewbankkit opened this issue Dec 6, 2020 · 2 comments · Fixed by #59
Closed

Multiple format verbs in conditional not handled correctly #38

ewbankkit opened this issue Dec 6, 2020 · 2 comments · Fixed by #59
Milestone

Comments

@ewbankkit
Copy link

ewbankkit commented Dec 6, 2020

My configuration (hashicorp/terraform-provider-aws#14013) is

cidr_block      = (%[2]q == "cidr_block") ? %[3]q : null
ipv6_cidr_block = (%[2]q == "ipv6_cidr_block") ? %[3]q : null

and terrafmt reports an error

failed to process with: failed to parse hcl: ./aws/resource_aws_route_table_test.go:69,48-49: Unbalanced parentheses; Expected a closing parenthesis to terminate the expression.
...
cidr_block      = (TFFMTKTBRACKETPERCENT[2]q == "cidr_block") ? %[3]q : null
ipv6_cidr_block = (TFFMTKTBRACKETPERCENT[2]q == "ipv6_cidr_block") ? %[3]q : null

This error seems to be in addition to the issue reported in #37.

@ewbankkit
Copy link
Author

This can usually be worked around via locals:

locals {
  attr_name  = %[2]q
  attr_value = %[3]q
}

cidr_block      = (local.attr_name == "cidr_block") ? local.attr_value : null
ipv6_cidr_block = (local.attr_name == "ipv6_cidr_block") ? local.attr_value : null

@gdavison
Copy link
Contributor

gdavison commented Feb 4, 2021

As a workaround until #41 is merged, you might be able to use %q instead of the indexed form %[2]q. The current code for handling formatting verbs doesn't support the indexed form after a (.

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