Skip to content

Commit 04c3f6d

Browse files
authored
adds support for provider functions (#162)
* adds support for provider functions
1 parent 912a805 commit 04c3f6d

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

hcl2/hcl2.lark

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ expr_term : "(" new_line_or_comment? expression new_line_or_comment? ")"
2727
| index_expr_term
2828
| get_attr_expr_term
2929
| identifier
30+
| provider_function_call
3031
| heredoc_template
3132
| heredoc_template_trim
3233
| attr_splat_expr_term
@@ -55,6 +56,8 @@ heredoc_template_trim : /<<-(?P<heredoc_trim>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*
5556

5657
function_call : identifier "(" new_line_or_comment? arguments? new_line_or_comment? ")"
5758
arguments : (expression (new_line_or_comment* "," new_line_or_comment* expression)* ("," | "...")? new_line_or_comment*)
59+
colons: "::"
60+
provider_function_call: identifier colons identifier colons identifier "(" new_line_or_comment? arguments? new_line_or_comment? ")"
5861

5962
index_expr_term : expr_term index
6063
get_attr_expr_term : expr_term get_attr

hcl2/transformer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ def function_call(self, args: List) -> str:
111111
args_str = ", ".join([str(arg) for arg in args[1] if arg is not Discard])
112112
return f"{args[0]}({args_str})"
113113

114+
def provider_function_call(self, args: List) -> str:
115+
args = self.strip_new_line_tokens(args)
116+
args_str = ""
117+
if len(args) > 5:
118+
args_str = ", ".join([str(arg) for arg in args[5] if arg is not Discard])
119+
provider_func = "::".join([args[0],args[2],args[4]])
120+
return f"{provider_func}({args_str})"
121+
114122
def arguments(self, args: List) -> List:
115123
return args
116124

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"locals": [
3+
{
4+
"name2": "${provider::test2::test(\"a\")}",
5+
"name3": "${test(\"a\")}"
6+
}
7+
]
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
locals {
2+
name2 = provider::test2::test("a")
3+
name3 = test("a")
4+
}

0 commit comments

Comments
 (0)