Detail:fmt.Sprintf("A module may have only one backend configuration. The backend was previously configured at %s.",m.Backend.DeclRange),
Subject:&b.DeclRange,
})
continue
}
m.Backend=b
}
for_,pc:=rangefile.ProviderConfigs{
key:=pc.moduleUniqueKey()
ifexisting,exists:=m.ProviderConfigs[key];exists{
ifexisting.Alias==""{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Duplicate provider configuration",
Detail:fmt.Sprintf("A default (non-aliased) provider configuration for %q was already given at %s. If multiple configurations are required, set the \"alias\" argument for alternative configurations.",existing.Name,existing.DeclRange),
Subject:&pc.DeclRange,
})
}else{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Duplicate provider configuration",
Detail:fmt.Sprintf("A provider configuration for %q with alias %q was already given at %s. Each configuration for the same provider must have a distinct alias.",existing.Name,existing.Alias,existing.DeclRange),
Detail:fmt.Sprintf("A variable named %q was already declared at %s. Variable names must be unique within a module.",existing.Name,existing.DeclRange),
Subject:&v.DeclRange,
})
}
m.Variables[v.Name]=v
}
for_,l:=rangefile.Locals{
ifexisting,exists:=m.Locals[l.Name];exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Duplicate local value definition",
Detail:fmt.Sprintf("A local value named %q was already defined at %s. Local value names must be unique within a module.",existing.Name,existing.DeclRange),
Subject:&l.DeclRange,
})
}
m.Locals[l.Name]=l
}
for_,o:=rangefile.Outputs{
ifexisting,exists:=m.Outputs[o.Name];exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Duplicate output definition",
Detail:fmt.Sprintf("An output named %q was already defined at %s. Output names must be unique within a module.",existing.Name,existing.DeclRange),
Subject:&o.DeclRange,
})
}
m.Outputs[o.Name]=o
}
for_,mc:=rangefile.ModuleCalls{
ifexisting,exists:=m.ModuleCalls[mc.Name];exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Duplicate module call",
Detail:fmt.Sprintf("An module call named %q was already defined at %s. Module calls must have unique names within a module.",existing.Name,existing.DeclRange),
Detail:fmt.Sprintf("A %s resource named %q was already declared at %s. Resource names must be unique per type in each module.",existing.Type,existing.Name,existing.DeclRange),
Subject:&r.DeclRange,
})
continue
}
m.ManagedResources[key]=r
}
for_,r:=rangefile.DataResources{
key:=r.moduleUniqueKey()
ifexisting,exists:=m.DataResources[key];exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:fmt.Sprintf("Duplicate data %q configuration",existing.Type),
Detail:fmt.Sprintf("A %s data resource named %q was already declared at %s. Resource names must be unique per type in each module.",existing.Type,existing.Name,existing.DeclRange),
// An override file with multiple backends is still invalid, even
// though it can override backends from _other_ files.
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Duplicate backend configuration",
Detail:fmt.Sprintf("Each override file may have only one backend configuration. A backend was previously configured at %s.",file.Backends[0].DeclRange),
Subject:&file.Backends[1].DeclRange,
})
}
}
for_,pc:=rangefile.ProviderConfigs{
key:=pc.moduleUniqueKey()
existing,exists:=m.ProviderConfigs[key]
ifpc.Alias==""{
// We allow overriding a non-existing _default_ provider configuration
// because the user model is that an absent provider configuration
// implies an empty provider configuration, which is what the user
// is therefore overriding here.
ifexists{
mergeDiags:=existing.merge(pc)
diags=append(diags,mergeDiags...)
}else{
m.ProviderConfigs[key]=pc
}
}else{
// For aliased providers, there must be a base configuration to
// override. This allows us to detect and report alias typos
// that might otherwise cause the override to not apply.
if!exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Missing base provider configuration for override",
Detail:fmt.Sprintf("There is no %s provider configuration with the alias %q. An override file can only override an aliased provider configuration that was already defined in a primary configuration file.",pc.Name,pc.Alias),
Summary:"Missing base variable declaration to override",
Detail:fmt.Sprintf("There is no variable named %q. An override file can only override a variable that was already declared in a primary configuration file.",v.Name),
Subject:&v.DeclRange,
})
continue
}
mergeDiags:=existing.merge(v)
diags=append(diags,mergeDiags...)
}
for_,l:=rangefile.Locals{
existing,exists:=m.Locals[l.Name]
if!exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Missing base local value definition to override",
Detail:fmt.Sprintf("There is no local value named %q. An override file can only override a local value that was already defined in a primary configuration file.",l.Name),
Subject:&l.DeclRange,
})
continue
}
mergeDiags:=existing.merge(l)
diags=append(diags,mergeDiags...)
}
for_,o:=rangefile.Outputs{
existing,exists:=m.Outputs[o.Name]
if!exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Missing base output definition to override",
Detail:fmt.Sprintf("There is no output named %q. An override file can only override an output that was already defined in a primary configuration file.",o.Name),
Subject:&o.DeclRange,
})
continue
}
mergeDiags:=existing.merge(o)
diags=append(diags,mergeDiags...)
}
for_,mc:=rangefile.ModuleCalls{
existing,exists:=m.ModuleCalls[mc.Name]
if!exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Missing module call to override",
Detail:fmt.Sprintf("There is no module call named %q. An override file can only override a module call that was defined in a primary configuration file.",mc.Name),
Subject:&mc.DeclRange,
})
continue
}
mergeDiags:=existing.merge(mc)
diags=append(diags,mergeDiags...)
}
for_,r:=rangefile.ManagedResources{
key:=r.moduleUniqueKey()
existing,exists:=m.ManagedResources[key]
if!exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Missing resource to override",
Detail:fmt.Sprintf("There is no %s resource named %q. An override file can only override a resource block defined in a primary configuration file.",r.Type,r.Name),
Subject:&r.DeclRange,
})
continue
}
mergeDiags:=existing.merge(r)
diags=append(diags,mergeDiags...)
}
for_,r:=rangefile.DataResources{
key:=r.moduleUniqueKey()
existing,exists:=m.DataResources[key]
if!exists{
diags=append(diags,&hcl.Diagnostic{
Severity:hcl.DiagError,
Summary:"Missing data resource to override",
Detail:fmt.Sprintf("There is no %s data resource named %q. An override file can only override a data block defined in a primary configuration file.",r.Type,r.Name),