Skip to content

Commit

Permalink
Merge pull request #36138 from hashicorp/backport/jbardin/templatefil…
Browse files Browse the repository at this point in the history
…e-marks/loosely-vocal-vulture

Backport of `templatefile` variables need to be unmarked for TypeFunc into v1.10
  • Loading branch information
jbardin authored Nov 29, 2024
2 parents 6a86088 + 26ff576 commit a3aad71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/lang/funcs/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions internal/lang/funcs/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
``,
},
{
Expand Down

0 comments on commit a3aad71

Please sign in to comment.