validate providers passed to a module exist
This validation was lost in the migration of inheritance back to core. Make sure a module configuraton doesn't specifiy a provider that doesn't exist.
This commit is contained in:
parent
f15d95fc4d
commit
8619f566bb
|
@ -390,7 +390,7 @@ func (c *Config) Validate() error {
|
||||||
|
|
||||||
// Check that providers aren't declared multiple times and that their
|
// Check that providers aren't declared multiple times and that their
|
||||||
// version constraints, where present, are syntactically valid.
|
// version constraints, where present, are syntactically valid.
|
||||||
providerSet := make(map[string]struct{})
|
providerSet := make(map[string]bool)
|
||||||
for _, p := range c.ProviderConfigs {
|
for _, p := range c.ProviderConfigs {
|
||||||
name := p.FullName()
|
name := p.FullName()
|
||||||
if _, ok := providerSet[name]; ok {
|
if _, ok := providerSet[name]; ok {
|
||||||
|
@ -410,7 +410,7 @@ func (c *Config) Validate() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
providerSet[name] = struct{}{}
|
providerSet[name] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all references to modules are valid
|
// Check that all references to modules are valid
|
||||||
|
@ -500,6 +500,15 @@ func (c *Config) Validate() error {
|
||||||
"%s: can't initialize configuration: %s",
|
"%s: can't initialize configuration: %s",
|
||||||
m.Id(), err))
|
m.Id(), err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check that all named providers actually exist
|
||||||
|
for _, p := range m.Providers {
|
||||||
|
if !providerSet[p] {
|
||||||
|
errs = append(errs, fmt.Errorf(
|
||||||
|
"provider %q named in module %q does not exist", p, m.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
dupped = nil
|
dupped = nil
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,12 @@ func TestConfigValidate_table(t *testing.T) {
|
||||||
true,
|
true,
|
||||||
"invalid version constraint",
|
"invalid version constraint",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"invalid provider name in module block",
|
||||||
|
"validate-missing-provider",
|
||||||
|
true,
|
||||||
|
"does not exist",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
provider "test" {
|
||||||
|
alias = "bar"
|
||||||
|
}
|
||||||
|
|
||||||
|
module "mod" {
|
||||||
|
source = "./mod"
|
||||||
|
providers = {
|
||||||
|
"test" = "test.foo"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue