configs: fix panic with provider aliases

addProviderRequirements() was incorrectly using the map keys from the module
provider configs when looking up the provider FQN. The map keys include
alias, so this resulted in a panic. Update addProviderRequirements() to
use the provider's name (only) when looking up the FQN.
This commit is contained in:
Kristin Laemmert 2020-06-02 09:29:59 -04:00
parent daa57ba9f6
commit 6fbd3942ea
2 changed files with 13 additions and 2 deletions

View File

@ -222,8 +222,8 @@ func (c *Config) addProviderRequirements(reqs getproviders.Requirements) hcl.Dia
} }
// "provider" block can also contain version constraints // "provider" block can also contain version constraints
for name, provider := range c.Module.ProviderConfigs { for _, provider := range c.Module.ProviderConfigs {
fqn := c.Module.ProviderForLocalConfig(addrs.LocalProviderConfig{LocalName: name}) fqn := c.Module.ProviderForLocalConfig(addrs.LocalProviderConfig{LocalName: provider.Name})
if _, ok := reqs[fqn]; !ok { if _, ok := reqs[fqn]; !ok {
// We'll at least have an unconstrained dependency then, but might // We'll at least have an unconstrained dependency then, but might
// add to this in the loop below. // add to this in the loop below.

View File

@ -162,3 +162,14 @@ func TestConfigProviderForConfigAddr(t *testing.T) {
t.Errorf("wrong result\ngot: %s\nwant: %s", got, want) t.Errorf("wrong result\ngot: %s\nwant: %s", got, want)
} }
} }
func TestConfigAddProviderRequirements(t *testing.T) {
cfg, diags := testModuleConfigFromFile("testdata/valid-files/providers-explicit-implied.tf")
assertNoDiagnostics(t, diags)
reqs := getproviders.Requirements{
addrs.NewDefaultProvider("null"): nil,
}
diags = cfg.addProviderRequirements(reqs)
assertNoDiagnostics(t, diags)
}