Skip to content

Commit

Permalink
configs: fix module for_each call bug (#31091)
Browse files Browse the repository at this point in the history
This fixes a bug introduced in 1879a39 in which initialising a module will fail
if that module contains both a provider block and a module call using for_each.
  • Loading branch information
kmoe committed May 20, 2022
1 parent 55edc6a commit 5417975
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions internal/configs/provider_validation.go
Expand Up @@ -30,28 +30,24 @@ func validateProviderConfigs(parentCall *ModuleCall, cfg *Config, noProviderConf

for name, child := range cfg.Children {
mc := mod.ModuleCalls[name]

childNoProviderConfigRange := noProviderConfigRange
// if the module call has any of count, for_each or depends_on,
// providers are prohibited from being configured in this module, or
// any module beneath this module.
// NOTE: If noProviderConfigRange was already set but we encounter
// a nested conflicting argument then we'll overwrite the caller's
// range, which allows us to report the problem as close to its
// cause as possible.
switch {
case mc.Count != nil:
noProviderConfigRange = mc.Count.Range().Ptr()
childNoProviderConfigRange = mc.Count.Range().Ptr()
case mc.ForEach != nil:
noProviderConfigRange = mc.ForEach.Range().Ptr()
childNoProviderConfigRange = mc.ForEach.Range().Ptr()
case mc.DependsOn != nil:
if len(mc.DependsOn) > 0 {
noProviderConfigRange = mc.DependsOn[0].SourceRange().Ptr()
childNoProviderConfigRange = mc.DependsOn[0].SourceRange().Ptr()
} else {
// Weird! We'll just use the call itself, then.
noProviderConfigRange = mc.DeclRange.Ptr()
childNoProviderConfigRange = mc.DeclRange.Ptr()
}
}
diags = append(diags, validateProviderConfigs(mc, child, noProviderConfigRange)...)
diags = append(diags, validateProviderConfigs(mc, child, childNoProviderConfigRange)...)
}

// the set of provider configuration names passed into the module, with the
Expand Down

0 comments on commit 5417975

Please sign in to comment.