Skip to content

stackmigrate: Fix recursive provider config resolution for resource instances in deeply nested modules#38528

Open
austinvalle wants to merge 3 commits intomainfrom
av/tf-37262
Open

stackmigrate: Fix recursive provider config resolution for resource instances in deeply nested modules#38528
austinvalle wants to merge 3 commits intomainfrom
av/tf-37262

Conversation

@austinvalle
Copy link
Copy Markdown
Member

@austinvalle austinvalle commented May 5, 2026

Fixes TF-37262


This PR fixes a bug with the MigrateTerraformState RPC when targeting deeply nested resources (introduced in #37060) that have implicit provider configurations.

Once the base case in the recursive findProviderConfig function 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

this is up for debate, we can also backport it if needed

1.16.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@austinvalle austinvalle requested a review from a team as a code owner May 5, 2026 22:12
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is a little gnarly, but the original test case was left intact while I added some plumbing for adding new test cases 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant