From 5ccb3c7c7add02b4b65a70cae9c2563ba0380579 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 27 Nov 2024 16:25:31 -0500 Subject: [PATCH] templatefile need to be unmarked for TypeFunc The templatefile function actually calls the full renderer within the TypeFunc to determine what the resulting might be, but that also requires unmarking the top-level of the vars map to strip marks even though the value is unused. --- internal/lang/funcs/filesystem.go | 3 ++- internal/lang/funcs/filesystem_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/lang/funcs/filesystem.go b/internal/lang/funcs/filesystem.go index 276dd12ce40a..07a978618fe5 100644 --- a/internal/lang/funcs/filesystem.go +++ b/internal/lang/funcs/filesystem.go @@ -126,10 +126,11 @@ func MakeTemplateFileFunc(baseDir string, funcsCb func() (funcs map[string]funct if err != nil { return cty.DynamicPseudoType, err } + vars, _ := args[1].UnmarkDeep() // This is safe even if args[1] contains unknowns because the HCL // template renderer itself knows how to short-circuit those. - val, err := renderTmpl(expr, args[1]) + val, err := renderTmpl(expr, vars) return val.Type(), err }, Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { diff --git a/internal/lang/funcs/filesystem_test.go b/internal/lang/funcs/filesystem_test.go index 35d39c9036e8..51b49abb11de 100644 --- a/internal/lang/funcs/filesystem_test.go +++ b/internal/lang/funcs/filesystem_test.go @@ -211,9 +211,9 @@ func TestTemplateFile(t *testing.T) { cty.StringVal("a"), cty.StringVal("b").Mark("var"), cty.StringVal("c"), - }), + }).Mark("vars"), }), - cty.StringVal("- a\n- b\n- c\n").Mark("path").Mark("var"), + cty.StringVal("- a\n- b\n- c\n").Mark("path").Mark("var").Mark("vars"), ``, }, {