diff --git a/configs/config.go b/configs/config.go index 0c07ba143..07040fa8b 100644 --- a/configs/config.go +++ b/configs/config.go @@ -35,6 +35,12 @@ type Config struct { // various elements (variables, resources, etc) defined by this module. Module *Module + // CallRange is the source range for the header of the module block that + // requested this module. + // + // This field is meaningless for the root module, where its contents are undefined. + CallRange hcl.Range + // SourceAddr is the source address that the referenced module was requested // from, as specified in configuration. // @@ -50,7 +56,11 @@ type Config struct { // Version is the specific version that was selected for this module, // based on version constraints given in configuration. // - // This field is meaningless for the root module, where its contents are undefined. + // This field is nil if the module was loaded from a non-registry source, + // since versions are not supported for other sources. + // + // This field is meaningless for the root module, where it will always + // be nil. Version *version.Version } diff --git a/configs/config_build.go b/configs/config_build.go index ecbf8bc47..0182426c1 100644 --- a/configs/config_build.go +++ b/configs/config_build.go @@ -30,11 +30,12 @@ func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config, for _, call := range calls { req := ModuleRequest{ - Name: call.Name, - SourceAddr: call.SourceAddr, - SourceAddrRange: call.SourceAddrRange, - VersionConstraints: []VersionConstraint{call.Version}, - Parent: parent, + Name: call.Name, + SourceAddr: call.SourceAddr, + SourceAddrRange: call.SourceAddrRange, + VersionConstraint: call.Version, + Parent: parent, + CallRange: call.DeclRange, } mod, ver, modDiags := walker.LoadModule(&req) @@ -50,6 +51,7 @@ func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config, Parent: parent, Root: parent.Root, Module: mod, + CallRange: call.DeclRange, SourceAddr: call.SourceAddr, SourceAddrRange: call.SourceAddrRange, Version: ver, @@ -110,12 +112,12 @@ type ModuleRequest struct { // to a non-existent object, etc. SourceAddrRange hcl.Range - // VersionConstraints are the constraints applied to the module in + // VersionConstraint is the version constraint applied to the module in // configuration. This data structure includes the source range for - // each constraint, which can and should be used to generate diagnostics + // the constraint, which can and should be used to generate diagnostics // about constraint-related issues, such as constraints that eliminate all // available versions of a module whose source is otherwise valid. - VersionConstraints []VersionConstraint + VersionConstraint VersionConstraint // Parent is the partially-constructed module tree node that the loaded // module will be added to. Callers may refer to any field of this @@ -124,4 +126,10 @@ type ModuleRequest struct { // The main reason this is provided is so that full module paths can // be constructed for uniqueness. Parent *Config + + // CallRange is the source range for the header of the "module" block + // in configuration that prompted this request. This can be used as the + // subject of an error diagnostic that relates to the module call itself, + // rather than to either its source address or its version number. + CallRange hcl.Range }