Skip to content

Commit

Permalink
fix: add for attribute identifier(#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhcli committed Jul 31, 2024
1 parent 98d401c commit fd2a769
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hcl2/hcl2.lark
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ block : identifier (identifier | STRING_LIT)* new_line_or_comment? "{" body "}"
new_line_and_or_comma: new_line_or_comment | "," | "," new_line_or_comment
new_line_or_comment: ( /\n/ | /#.*\n/ | /\/\/.*\n/ )+

identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ | IN
identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ | IN | FOR
IN : "in"
FOR : "for"

?expression : expr_term | operation | conditional

Expand Down
2 changes: 1 addition & 1 deletion hcl2/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def provider_function_call(self, args: List) -> str:
args_str = ""
if len(args) > 5:
args_str = ", ".join([str(arg) for arg in args[5] if arg is not Discard])
provider_func = "::".join([args[0],args[2],args[4]])
provider_func = "::".join([args[0], args[2], args[4]])
return f"{provider_func}({args_str})"

def arguments(self, args: List) -> List:
Expand Down
13 changes: 13 additions & 0 deletions test/helpers/terraform-config-json/resource_for_attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"resource": [
{
"custom_provider_resource": {
"resource_name": {
"name": "resource_name",
"attribute": "attribute_value",
"for": "attribute_value2"
}
}
}
]
}
5 changes: 5 additions & 0 deletions test/helpers/terraform-config/resource_for_attribute.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "custom_provider_resource" "resource_name" {
name = "resource_name"
attribute = "attribute_value"
for = "attribute_value2"
}

0 comments on commit fd2a769

Please sign in to comment.