returncty.DynamicVal,function.NewArgErrorf(1,"invalid vars value: must be a map")// or an object, but we don't strongly distinguish these most of the time
}
ctx:=&hcl.EvalContext{
Variables:varsVal.AsValueMap(),
}
// We require all of the variables to be valid HCL identifiers, because
// otherwise there would be no way to refer to them in the template
// anyway. Rejecting this here gives better feedback to the user
// than a syntax error somewhere in the template itself.
forn:=rangectx.Variables{
if!hclsyntax.ValidIdentifier(n){
// This error message intentionally doesn't describe _all_ of
// the different permutations that are technically valid as an
// HCL identifier, but rather focuses on what we might
// consider to be an "idiomatic" variable name.
returncty.DynamicVal,function.NewArgErrorf(1,"invalid template variable name %q: must start with a letter, followed by zero or more letters, digits, and underscores",n)
}
}
// We'll pre-check references in the template here so we can give a
// more specialized error message than HCL would by default, so it's
// clearer that this problem is coming from a templatefile call.
for_,traversal:=rangeexpr.Variables(){
root:=traversal.RootName()
if_,ok:=ctx.Variables[root];!ok{
returncty.DynamicVal,function.NewArgErrorf(1,"vars map does not contain key %q, referenced at %s",root,traversal[0].SourceRange())
}
}
givenFuncs:=funcsCb()// this callback indirection is to avoid chicken/egg problems