terraform state replace-provider command replaces the provider for resources in the Terraform state. This is useful when a provider is forked or changes its fully-qualified name.
Synopsis
Replace provider in the state.Usage
Options
Skip interactive approval.
Don’t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.
Duration to retry a state lock.
A rare option used for the remote backend only. See the remote backend documentation for more information.
Path to the state file. Legacy option supported for the local backend only.
Path where Terraform should write the backup state. Legacy option supported for the local backend only.
Arguments
The fully-qualified provider name to replace. Format:
registry.terraform.io/namespace/providerThe new fully-qualified provider name. Format:
registry.terraform.io/namespace/providerExamples
Replace provider after fork
Replace a provider that has been forked to a new namespace:Auto-approve the replacement
Skip the interactive confirmation:Replace with custom registry
Replace a provider with one from a custom registry:Replace provider shorthand
Replace using provider shorthand (hashicorp namespace is implied):Common Use Cases
Provider fork migration
When a community provider is forked from the official HashiCorp provider:Provider namespace change
When a provider moves to a different namespace:Custom provider registry
When migrating from public registry to a private/custom registry:Legacy provider migration
Migrating from legacy provider addresses to fully-qualified names:Workflow
Typical workflow for replacing a provider:- Update required_providers block in your Terraform configuration:
- Run terraform init to download the new provider:
- Replace the provider in state:
- Verify the changes:
Important Notes
- This command only updates the provider reference in the state file
- It does not modify your Terraform configuration files
- You must manually update the
required_providersblock in your configuration - The old and new providers must be compatible (same resource schemas)
- If providers are incompatible, you may see errors during
terraform plan - A backup of the state is automatically created before changes
- All resources using the old provider will be updated to use the new provider
Interactive Approval
By default, the command shows:- The provider change (from → to)
- A list of all affected resources
- A confirmation prompt
yes to proceed. Any other input cancels the operation.
Use -auto-approve to skip this prompt (useful in automation).
Provider Compatibility
Before replacing a provider, ensure:- The new provider has the same resource types
- Resource schemas are compatible
- The provider API is compatible
- Errors during
terraform plan - Unexpected infrastructure changes
- Resource recreation