- The Command Line
- Basic CLI Features
- Command: state
- Command: state replace-provider
Command: state replace-provider
The tofu state replace-provider
command is used to replace the provider
for resources in a OpenTofu state.
Usage
Usage: tofu state replace-provider [options] FROM_PROVIDER_FQN TO_PROVIDER_FQN
This command will update all resources using the "from" provider, setting the provider to the specified "to" provider. This allows changing the source of a provider which currently has resources in state.
This command will output a backup copy of the state prior to saving any changes. The backup cannot be disabled. Due to the destructive nature of this command, backups are required.
Use of variables in module sources,
backend configuration,
or encryption block
requires assigning values to root module variables
when running tofu state replace-providers
.
This command also accepts the following options:
-
-auto-approve
- Skip interactive approval. -
-lock=false
- Don't hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace. -
-lock-timeout=0s
- Duration to retry a state lock. -
-var 'NAME=VALUE'
- Sets a value for a single input variable declared in the root module of the configuration. Use this option multiple times to set more than one variable. Refer to Input Variables on the Command Line for more information. -
-var-file=FILENAME
- Sets values for potentially many input variables declared in the root module of the configuration, using definitions from a "tfvars" file. Use this option multiple times to include values from more than one file.
There are several other ways to set values for input variables in the root
module, aside from the -var
and -var-file
options. Refer to
Assigning Values to Root Module Variables for more information.
For configurations using the cloud
backend or the remote
backend
only, tofu state replace-provider
also accepts the option
-ignore-remote-version
.
For configurations using
the local
state only,
tofu state replace-provider
also accepts the legacy options
-state
, -state-out
, and -backup
.
Example
The example below replaces the hashicorp/aws
provider with a fork by acme
, hosted at a private registry at registry.acme.corp
: