From 6fbd3942ea6a2e456d43467a64d34fe81dd08274 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Tue, 2 Jun 2020 09:29:59 -0400 Subject: [PATCH] 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. --- configs/config.go | 4 ++-- configs/config_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/configs/config.go b/configs/config.go index 39a0b717d..a99e90cad 100644 --- a/configs/config.go +++ b/configs/config.go @@ -222,8 +222,8 @@ func (c *Config) addProviderRequirements(reqs getproviders.Requirements) hcl.Dia } // "provider" block can also contain version constraints - for name, provider := range c.Module.ProviderConfigs { - fqn := c.Module.ProviderForLocalConfig(addrs.LocalProviderConfig{LocalName: name}) + for _, provider := range c.Module.ProviderConfigs { + fqn := c.Module.ProviderForLocalConfig(addrs.LocalProviderConfig{LocalName: provider.Name}) if _, ok := reqs[fqn]; !ok { // We'll at least have an unconstrained dependency then, but might // add to this in the loop below. diff --git a/configs/config_test.go b/configs/config_test.go index e33e236da..b2cefe751 100644 --- a/configs/config_test.go +++ b/configs/config_test.go @@ -162,3 +162,14 @@ func TestConfigProviderForConfigAddr(t *testing.T) { 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) +}