{"record":{"id":"b353a4c25068ce10","repo":"pulumi/pulumi","slug":"state-migration-for-s-removes-or-renames-provider","errorCode":null,"errorMessage":"state migration for %s removes or renames provider state %s; provider states must be returned unchanged","messagePattern":"state migration for (.+?) removes or renames provider state (.+?); provider states must be returned unchanged","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resource/deploy/state_migration_validation.go","lineNumber":208,"sourceCode":") error {\n\toriginalProviders := make(map[resource.URN]apitype.ResourceV3)\n\tfor _, state := range original {\n\t\tif sdkproviders.IsProviderType(state.Type) {\n\t\t\toriginalProviders[state.URN] = state\n\t\t}\n\t}\n\n\tfinalProviders := make(map[resource.URN]apitype.ResourceV3)\n\tfor _, state := range final {\n\t\tif sdkproviders.IsProviderType(state.Type) {\n\t\t\tfinalProviders[state.URN] = state\n\t\t}\n\t}\n\n\tfor providerURN, originalState := range originalProviders {\n\t\tfinalState, ok := finalProviders[providerURN]\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"state migration for %s removes or renames provider state %s; \"+\n\t\t\t\t\"provider states must be returned unchanged\", urn, providerURN)\n\t\t}\n\t\tif !reflect.DeepEqual(originalState, finalState) {\n\t\t\treturn fmt.Errorf(\"state migration for %s changes provider state %s; \"+\n\t\t\t\t\"provider states must be returned unchanged\", urn, providerURN)\n\t\t}\n\t}\n\tfor providerURN := range finalProviders {\n\t\tif _, ok := originalProviders[providerURN]; !ok {\n\t\t\treturn fmt.Errorf(\"state migration for %s introduces provider state %s; \"+\n\t\t\t\t\"provider states cannot be created by a state migration\", urn, providerURN)\n\t\t}\n\t}\n\treturn nil\n}\n\n// validateStateMigrationResult checks that ResultSubtree is well-formed before using it to rewrite the prior snapshot:\n// the registering resource's state must be present, all result states must be parented transitively to it, and no","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/resource/deploy/state_migration_validation.go#L190-L226","documentation":"A state migration (e.g. a migrateResource callback in a legacy provider/plugin transforming snapshot state) dropped or renamed a provider resource that existed in the original snapshot. The engine requires provider states to pass through migrations untouched, because the provider registry matches resources by the provider's exact URN and normalized checkpoint representation; rewriting them would orphan configured plugin instances. This error is thrown by validateStateMigrationProviderStates after comparing provider URNs in the original vs final state sets.","triggerScenarios":"Running a deployment whose state migration result subtree omits a provider resource present in the prior snapshot, or returns it under a different URN (e.g. the migration rebuilt the provider URN with a new name/parent instead of copying it verbatim).","commonSituations":"Writing a migrateResource callback that reconstructs child resources but forgets to carry the provider resource; renaming a resource that also had a provider role; alias-based lookups where the migration re-registers the provider under the new URN.","solutions":["Update the migration so it copies provider resources from the original state into the result unchanged (same URN, same normalized fields).","If the provider URN legitimately changed (rename), first run the migration without renaming the provider, then apply the rename in a separate step via the normal pulumi rename flow.","Inspect the migration output with `pulumi stack export` before/after to confirm the provider entry's URN and fields are byte-identical."],"exampleFix":"// before: migration rebuilds provider with new URN\nresult := append(children, migrateProviderWithNewURN(old))\n// after: pass provider state through untouched\nresult := append(children, oldProviderState)","handlingStrategy":"validation","validationCode":"// Compare provider URN sets before/after running your migration locally\nbefore := newSet(stackExportBefore)\nafter := newSet(stackExportAfter)\nfor urn := range before.providers {\n    if _, ok := after.providers[urn]; !ok {\n        return fmt.Errorf(\"migration would drop provider %s\", urn)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runMigration(); err != nil {\n    if strings.Contains(err.Error(), \"removes or renames provider state\") {\n        // roll back and re-copy provider states verbatim\n    }\n    return err\n}","preventionTips":["Always copy provider apitype.ResourceV3 values by value, never rebuild them in migrations.","Snapshot `pulumi stack export` before running any migration and diff afterwards.","Test migrations against a copy of real stack state, not synthetic fixtures."],"tags":["state-migration","provider","snapshot"],"backgroundTag":"provider-state-mutation-during-migration","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}