Skip to content

Commit 6fbd394

Browse files
committed
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.
1 parent daa57ba commit 6fbd394

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

configs/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ func (c *Config) addProviderRequirements(reqs getproviders.Requirements) hcl.Dia
222222
}
223223

224224
// "provider" block can also contain version constraints
225-
for name, provider := range c.Module.ProviderConfigs {
226-
fqn := c.Module.ProviderForLocalConfig(addrs.LocalProviderConfig{LocalName: name})
225+
for _, provider := range c.Module.ProviderConfigs {
226+
fqn := c.Module.ProviderForLocalConfig(addrs.LocalProviderConfig{LocalName: provider.Name})
227227
if _, ok := reqs[fqn]; !ok {
228228
// We'll at least have an unconstrained dependency then, but might
229229
// add to this in the loop below.

configs/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,14 @@ func TestConfigProviderForConfigAddr(t *testing.T) {
162162
t.Errorf("wrong result\ngot: %s\nwant: %s", got, want)
163163
}
164164
}
165+
166+
func TestConfigAddProviderRequirements(t *testing.T) {
167+
cfg, diags := testModuleConfigFromFile("testdata/valid-files/providers-explicit-implied.tf")
168+
assertNoDiagnostics(t, diags)
169+
170+
reqs := getproviders.Requirements{
171+
addrs.NewDefaultProvider("null"): nil,
172+
}
173+
diags = cfg.addProviderRequirements(reqs)
174+
assertNoDiagnostics(t, diags)
175+
}

0 commit comments

Comments
 (0)