Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hcl2/hcl2.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,8 @@ heredoc_template_trim : /<<-(?P<heredoc_trim>[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
attr_splat_expr_term : expr_term attr_splat
Expand Down
10 changes: 9 additions & 1 deletion hcl2/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, TYPE_CHECKING

from lark import Transformer, Token
from lark.visitors import v_args
from lark.visitors import v_args, Discard

if TYPE_CHECKING:
from lark.tree import Meta
Expand Down Expand Up @@ -107,6 +107,14 @@ def function_call(self, args: list) -> str:
def arguments(self, args: list) -> list:
return args

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})"

@v_args(meta=True)
def block(self, meta: Meta, args: list) -> dict[str, Any]:
args = self.strip_new_line_tokens(args)
Expand Down
10 changes: 10 additions & 0 deletions test/helpers/terraform-config-json/provider_function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"locals": [
{
"name2": ["${provider::test2::test(\"a\")}"],
"name3": ["${test(\"a\")}"],
"__end_line__": 4,
"__start_line__": 1
}
]
}
4 changes: 4 additions & 0 deletions test/helpers/terraform-config/provider_function.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
locals {
name2 = provider::test2::test("a")
name3 = test("a")
}