configs: fix module for_each call bug #31091
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a bug introduced in #30639 in which initialising a module will fail if that module contains both a provider block and a module call using
for_each
.This bug was introduced in https://github.com/hashicorp/terraform/pull/30639/files#diff-95e614048e1ba4ba7621e22ba67cfe5c8acd386e5540b8c92c267d2fd1b3d31eR31-R55 by removing a variable scoped to a
for
loop (var nope
) and instead overwritingnoProviderConfigRange
. This meant that the error at https://github.com/hashicorp/terraform/pull/30639/files#diff-95e614048e1ba4ba7621e22ba67cfe5c8acd386e5540b8c92c267d2fd1b3d31eR181 would be triggered if the parent module contained a provider block, not the child.Fixes #31081
Test case
There are no tests in code for this behaviour. Highly recommend adding them as follow up. I manually tested this using the example below, kindly provided by @knbnnate.
main.tf
barren_child/main.tf
grandchild/main.tf