stackmigrate: Fix recursive provider config resolution for resource instances in deeply nested modules#38528
Open
austinvalle wants to merge 3 commits intomainfrom
Open
stackmigrate: Fix recursive provider config resolution for resource instances in deeply nested modules#38528austinvalle wants to merge 3 commits intomainfrom
austinvalle wants to merge 3 commits intomainfrom
Conversation
…nstances in deeply nested modules
austinvalle
commented
May 5, 2026
Member
Author
There was a problem hiding this comment.
This diff is a little gnarly, but the original test case was left intact while I added some plumbing for adding new test cases 👍🏻
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes TF-37262
This PR fixes a bug with the
MigrateTerraformStateRPC when targeting deeply nested resources (introduced in #37060) that have implicit provider configurations.Once the base case in the recursive
findProviderConfigfunction has been returned, there is no reason to lookup the provider again with the resource as the base case has already returned that information. (and doing so will just return a diagnostic when we have deeply nested modules like this, which will lookup the resource in each parent module)Here are the new tests failing without the proposed fix:
--- FAIL: TestStacksMigrateTerraformState (0.01s) --- FAIL: TestStacksMigrateTerraformState/nested-modules-with-implicit-provider-config-quux (0.00s) /Users/austin.valle/code/terraform/internal/rpcapi/stacks_test.go:2038: unexpected diags: [severity:ERROR summary:"Resource mapped to non-existent target" detail:"Could not migrate resource \"testing_deferred_resource.resource\". Resource \"module.child.module.grand-child.testing_deferred_resource.resource\" not found component \"component.self\"."] --- FAIL: TestMigrate (0.02s) --- FAIL: TestMigrate/deeply_nested_module_resources_with_implicit_provider_configs (0.00s) /Users/austin.valle/code/terraform/internal/stacks/stackmigrate/migrate_test.go:1611: unexpected diagnostics difference: tfdiags.Diagnostics{ + &tfdiags.rpcFriendlyDiag{ + Severity_: s"Error", + Summary_: "Resource mapped to non-existent target", + Detail_: `Could not migrate resource "testing_resource.data". Resource "module.child_mod.module.grand_child_mod.testing_resource.grand_chi`..., + }, + &tfdiags.rpcFriendlyDiag{ + Severity_: s"Error", + Summary_: "Resource mapped to non-existent target", + Detail_: `Could not migrate resource "testing_resource.another[0]". Resource "module.child_mod.module.grand_child_mod.testing_resource.ano`..., + }, + &tfdiags.rpcFriendlyDiag{ + Severity_: s"Error", + Summary_: "Resource mapped to non-existent target", + Detail_: `Could not migrate resource "testing_resource.another[1]". Resource "module.child_mod.module.grand_child_mod.testing_resource.ano`..., + }, }Target Release
1.16.x
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry