pulumi/pulumi · error

state migration for removes or renames provider state …

Error message

state migration for %s removes or renames provider state %s; provider states must be returned unchanged

What it means

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.

Solutions

  1. Update the migration so it copies provider resources from the original state into the result unchanged (same URN, same normalized fields).
  2. 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.
  3. Inspect the migration output with `pulumi stack export` before/after to confirm the provider entry's URN and fields are byte-identical.

Example fix

// before: migration rebuilds provider with new URN
result := append(children, migrateProviderWithNewURN(old))
// after: pass provider state through untouched
result := append(children, oldProviderState)
Defensive patterns

Strategy: validation

Validate before calling

// Compare provider URN sets before/after running your migration locally
before := newSet(stackExportBefore)
after := newSet(stackExportAfter)
for urn := range before.providers {
    if _, ok := after.providers[urn]; !ok {
        return fmt.Errorf("migration would drop provider %s", urn)
    }
}

Try / catch

if err := runMigration(); err != nil {
    if strings.Contains(err.Error(), "removes or renames provider state") {
        // roll back and re-copy provider states verbatim
    }
    return err
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/b353a4c25068ce10. Report an issue: GitHub.

Appendix: source

Thrown at pkg/resource/deploy/state_migration_validation.go:208

) error {
	originalProviders := make(map[resource.URN]apitype.ResourceV3)
	for _, state := range original {
		if sdkproviders.IsProviderType(state.Type) {
			originalProviders[state.URN] = state
		}
	}

	finalProviders := make(map[resource.URN]apitype.ResourceV3)
	for _, state := range final {
		if sdkproviders.IsProviderType(state.Type) {
			finalProviders[state.URN] = state
		}
	}

	for providerURN, originalState := range originalProviders {
		finalState, ok := finalProviders[providerURN]
		if !ok {
			return fmt.Errorf("state migration for %s removes or renames provider state %s; "+
				"provider states must be returned unchanged", urn, providerURN)
		}
		if !reflect.DeepEqual(originalState, finalState) {
			return fmt.Errorf("state migration for %s changes provider state %s; "+
				"provider states must be returned unchanged", urn, providerURN)
		}
	}
	for providerURN := range finalProviders {
		if _, ok := originalProviders[providerURN]; !ok {
			return fmt.Errorf("state migration for %s introduces provider state %s; "+
				"provider states cannot be created by a state migration", urn, providerURN)
		}
	}
	return nil
}

// validateStateMigrationResult checks that ResultSubtree is well-formed before using it to rewrite the prior snapshot:
// the registering resource's state must be present, all result states must be parented transitively to it, and no

View on GitHub (pinned to 793f7b2e16)