From 23636b8e722de5eee3f50ae4e637f6c81e927027 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Fri, 20 May 2022 11:17:27 +0100 Subject: [PATCH] configs: fix module for_each call bug 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. --- internal/configs/provider_validation.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/internal/configs/provider_validation.go b/internal/configs/provider_validation.go index 0e6452c26b16..56262bb2aab3 100644 --- a/internal/configs/provider_validation.go +++ b/internal/configs/provider_validation.go @@ -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