// Verify that any module calls only refer to named providers, and that
// those providers will have a configuration at runtime. This way we can
// direct users where to add the missing configuration, because the runtime
// error is only "missing provider X".
for_,modCall:=rangemod.ModuleCalls{
for_,passed:=rangemodCall.Providers{
// aliased providers are handled more strictly, and are never
// inherited, so they are validated within modules further down.
// Skip these checks to prevent redundant diagnostics.
ifpassed.InParent.Alias!=""{
continue
}
name:=passed.InParent.String()
_,confOK:=configured[name]
_,localOK:=localNames[name]
_,passedOK:=passedIn[name]
// This name was not declared somewhere within in the
// configuration. We ignore empty configs, because they will
// already produce a warning.
if!(confOK||localOK){
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagWarning,
Summary:fmt.Sprintf("Provider %s is undefined",name),
Detail:fmt.Sprintf("No provider named %s has been declared in %s.\n",name,moduleText)+
fmt.Sprintf("If you wish to refer to the %s provider within the module, add a provider configuration, or an entry in the required_providers block.",name),
Subject:&passed.InParent.NameRange,
})
continue
}
// Now we may have named this provider within the module, but
// there won't be a configuration available at runtime if the
// parent module did not pass one in.
if!cfg.Path.IsRoot()&&!(confOK||passedOK){
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagWarning,
Summary:fmt.Sprintf("No configuration passed in for provider %s in %s",name,cfg.Path),
Detail:fmt.Sprintf("Provider %s is referenced within %s, but no configuration has been supplied.\n",name,moduleText)+
fmt.Sprintf("Add a provider named %s to the providers map for %s in %s.",name,cfg.Path,parentModuleText),
Subject:&passed.InParent.NameRange,
})
}
}
}
ifcfg.Path.IsRoot(){
// nothing else to do in the root module
returndiags
}
// there cannot be any configurations if no provider config is allowed
pass-inherited-provider/mod/main.tf:15,16-20: No configuration passed in for provider test in module.mod; Provider test is referenced within module.mod, but no configuration has been supplied