From 833b07436f8bb646a032c200d3b469d7cbb4a9c9 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 27 Nov 2024 10:01:59 -0500 Subject: [PATCH] template variables may be entirely unknown While the evaluator can deal with unknown template variables, if the entire map of variables is unknown, we can't create the map and need to short-circuit the call. --- internal/lang/funcs/filesystem.go | 2 +- internal/lang/funcs/filesystem_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/lang/funcs/filesystem.go b/internal/lang/funcs/filesystem.go index 289a09ea9083..276dd12ce40a 100644 --- a/internal/lang/funcs/filesystem.go +++ b/internal/lang/funcs/filesystem.go @@ -137,7 +137,7 @@ func MakeTemplateFileFunc(baseDir string, funcsCb func() (funcs map[string]funct vars, varsMarks := args[1].UnmarkDeep() - if !pathArg.IsKnown() { + if !pathArg.IsKnown() || !vars.IsKnown() { return cty.UnknownVal(retType).WithMarks(pathMarks, varsMarks), nil } diff --git a/internal/lang/funcs/filesystem_test.go b/internal/lang/funcs/filesystem_test.go index 5439661424c4..35d39c9036e8 100644 --- a/internal/lang/funcs/filesystem_test.go +++ b/internal/lang/funcs/filesystem_test.go @@ -216,6 +216,12 @@ func TestTemplateFile(t *testing.T) { cty.StringVal("- a\n- b\n- c\n").Mark("path").Mark("var"), ``, }, + { + cty.StringVal("testdata/list.tmpl").Mark("path"), + cty.UnknownVal(cty.Map(cty.String)), + cty.DynamicVal.Mark("path"), + ``, + }, { cty.StringVal("testdata/list.tmpl").Mark("path"), cty.ObjectVal(map[string]cty.Value{