Instead of evaluating and parsing a module source and version on
configuration loading, we now simply store the expression.
Decoding is now done during the graph-based configuration loading in the
module install node.
pull/38232/head
Daniel Banck3 months agocommitted byDaniel Schmidt
// NOTE: We leave mc.SourceAddr as nil for any situation where the
// source attribute is invalid, so any code which tries to carefully
// use the partial result of a failed config decode must be
// resilient to that.
mc.SourceAddr=nil
// NOTE: In practice it's actually very unlikely to end up here,
// because our source address parser can turn just about any string
// into some sort of remote package address, and so for most errors
// we'll detect them only during module installation. There are
// still a _few_ purely-syntax errors we can catch at parsing time,
// though, mostly related to remote package sub-paths and local
// paths.
switcherr:=err.(type){
case*moduleaddrs.MaybeRelativePathErr:
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Invalid module source address",
Detail:fmt.Sprintf(
"Terraform failed to determine your intended installation method for remote module package %q.\n\nIf you intended this as a path relative to the current module, use \"./%s\" instead. The \"./\" prefix indicates that the address is a relative filesystem path.",
err.Addr,err.Addr,
),
Subject:mc.SourceAddrRange.Ptr(),
})
default:
ifhaveVersionArg{
// In this case we'll include some extra context that
// we assumed a registry source address due to the
// version argument.
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Invalid registry module source address",
Detail:fmt.Sprintf("Failed to parse module registry address: %s.\n\nTerraform assumed that you intended a module registry source address because you also set the argument \"version\", which applies only to registry modules.",err),
Subject:mc.SourceAddrRange.Ptr(),
})
}else{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Invalid module source address",
Detail:fmt.Sprintf("Failed to parse module source address: %s.",err),