This commit is contained in:
Philippe Caseiro 2022-06-30 09:52:46 +02:00
parent e47d2f64df
commit d10e0e1194
1 changed files with 3 additions and 3 deletions

View File

@ -133,20 +133,20 @@ func (cf *ConfigFile) processHCLTemplate(file string, config []byte) (string, er
for n := range ctx.Variables { for n := range ctx.Variables {
if !hclsyntax.ValidIdentifier(n) { if !hclsyntax.ValidIdentifier(n) {
panic(fmt.Errorf("invalid template variable name %q: must start with a letter, followed by zero or more letters, digits, and underscores", n)) return "", fmt.Errorf("invalid template variable name %q: must start with a letter, followed by zero or more letters, digits, and underscores", n)
} }
} }
for _, traversal := range expr.Variables() { for _, traversal := range expr.Variables() {
root := traversal.RootName() root := traversal.RootName()
if _, ok := ctx.Variables[root]; !ok { if _, ok := ctx.Variables[root]; !ok {
panic(fmt.Errorf("vars map does not contain key %q, referenced at %s", root, traversal[0].SourceRange())) return "", fmt.Errorf("vars map does not contain key %q, referenced at %s", root, traversal[0].SourceRange())
} }
} }
val, diags := expr.Value(ctx) val, diags := expr.Value(ctx)
if diags.HasErrors() { if diags.HasErrors() {
panic(diags.Error()) return "", diags
} }
return val.AsString(), nil return val.AsString(), nil