Use the new FunctionCallUnknownDiagExtra feature from hcl to help guide
users through problems with provider function calls.
Now that we can detect diagnostics from unknown function calls, we can
correlate the namespace and names with certain problems specific to
Terraform.
// help if the user is skipping the provider:: prefix before the
// provider name.
d.Detail=fmt.Sprintf(`The function namespace %q is not valid. Provider function calls must use the "provider::" namespace prefix.`,namespaceParts[0])
continue
}
ifnamespaceParts[1]==""{
// missing provider name entirely
d.Detail=`The function call must include the provider name after the "provider::" prefix.`
continue
}
ifd.EvalContext==nil{
// There's no eval context for some reason, so we can't inspect the
// available functions.
d.Detail=fmt.Sprintf(`There is no function named "%s%s".`,namespace,name)
continue
}
otherProviderFuncs:=false
forfuncName:=ranged.EvalContext.Functions{
// there are other functions in this provider namespace, so it must
// have been included in the configuration, and we can be clear that
// this a function which the provider does not support.
ifstrings.HasPrefix(funcName,namespace){
otherProviderFuncs=true
break
}
}
ifotherProviderFuncs{
d.Detail=fmt.Sprintf("The function %q is not available from the provider %q.",name,namespaceParts[1])
continue
}
// no other functions exist for this provider, so hint that the user may
// need to include it in the configuration.
d.Detail=fmt.Sprintf(`There is no function named "%s%s". The provider %q may need to be added to the required_providers block within the module configuration.`,namespace,name,namespaceParts[1])