diff --git a/hcl2/hcl2.lark b/hcl2/hcl2.lark index b9e453c7..cee792e8 100644 --- a/hcl2/hcl2.lark +++ b/hcl2/hcl2.lark @@ -27,6 +27,7 @@ expr_term : "(" new_line_or_comment? expression new_line_or_comment? ")" | index_expr_term | get_attr_expr_term | identifier + | provider_function_call | heredoc_template | heredoc_template_trim | attr_splat_expr_term @@ -55,6 +56,8 @@ heredoc_template_trim : /<<-(?P[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)* function_call : identifier "(" new_line_or_comment? arguments? new_line_or_comment? ")" arguments : (expression (new_line_or_comment* "," new_line_or_comment* expression)* ("," | "...")? new_line_or_comment*) +colons: "::" +provider_function_call: identifier colons identifier colons identifier "(" new_line_or_comment? arguments? new_line_or_comment? ")" index_expr_term : expr_term index get_attr_expr_term : expr_term get_attr diff --git a/hcl2/transformer.py b/hcl2/transformer.py index 6f2d4f31..998a9dd1 100644 --- a/hcl2/transformer.py +++ b/hcl2/transformer.py @@ -111,6 +111,14 @@ def function_call(self, args: List) -> str: args_str = ", ".join([str(arg) for arg in args[1] if arg is not Discard]) return f"{args[0]}({args_str})" + def provider_function_call(self, args: List) -> str: + args = self.strip_new_line_tokens(args) + 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]]) + return f"{provider_func}({args_str})" + def arguments(self, args: List) -> List: return args diff --git a/test/helpers/terraform-config-json/provider_function.json b/test/helpers/terraform-config-json/provider_function.json new file mode 100644 index 00000000..2b749c13 --- /dev/null +++ b/test/helpers/terraform-config-json/provider_function.json @@ -0,0 +1,8 @@ +{ + "locals": [ + { + "name2": "${provider::test2::test(\"a\")}", + "name3": "${test(\"a\")}" + } + ] +} diff --git a/test/helpers/terraform-config/provider_function.tf b/test/helpers/terraform-config/provider_function.tf new file mode 100644 index 00000000..feaca9b7 --- /dev/null +++ b/test/helpers/terraform-config/provider_function.tf @@ -0,0 +1,4 @@ +locals { + name2 = provider::test2::test("a") + name3 = test("a") +}