# atmos terraform state replace-provider

Use this command to replace a provider in the Terraform state for an Atmos component in a stack.

## Usage

Execute the `terraform state replace-provider` command like this:

```shell
atmos terraform state replace-provider <component> -s <stack> <from-provider> <to-provider> [options]
```

This command replaces the provider source for all resources managed by the specified provider. This is useful when a provider has been renamed, moved to a different namespace, or forked.

:::caution
State manipulation commands should be used carefully. Always back up your state before making changes.
:::

:::tip
Run `atmos terraform state replace-provider --help` to see all the available options
:::

## Examples

```shell
# Replace a provider namespace
atmos terraform state replace-provider vpc -s dev \
  "registry.terraform.io/-/aws" \
  "registry.terraform.io/hashicorp/aws"

# Replace a forked provider
atmos terraform state replace-provider vpc -s dev \
  "registry.terraform.io/hashicorp/aws" \
  "registry.terraform.io/my-org/aws"
```

## Arguments

- **`component` (required)**

  Atmos terraform component.
- **`from-provider` (required)**

  The source provider address to replace (e.g., `registry.terraform.io/-/aws`).
- **`to-provider` (required)**

  The target provider address to replace with (e.g., `registry.terraform.io/hashicorp/aws`).

## Flags

- **`--stack` (alias `-s`) (required)**

  Atmos stack.
- **`--dry-run` (optional)**

  Show what would be executed without actually running the command.
  ```shell
  atmos terraform state replace-provider vpc -s dev --dry-run old-provider new-provider
  ```
- **`--skip-init` (optional)**

  Skip running `terraform init` before executing the command.
  ```shell
  atmos terraform state replace-provider vpc -s dev --skip-init old-provider new-provider
  ```

## Native Terraform Flags

The `atmos terraform state replace-provider` command supports native `terraform state replace-provider` flags. Pass them directly or use `--` to separate Atmos flags from Terraform flags.

- **`-auto-approve`**

  Skip interactive approval of the provider replacement.
  ```shell
  atmos terraform state replace-provider vpc -s dev -auto-approve old-provider new-provider
  ```
- **`-lock=true`**

  Lock the state file when locking is supported. Defaults to `true`.
  ```shell
  atmos terraform state replace-provider vpc -s dev -lock=false old-provider new-provider
  ```
- **`-lock-timeout=DURATION`**

  Duration to retry a state lock. Defaults to `0s`.
  ```shell
  atmos terraform state replace-provider vpc -s dev -lock-timeout=30s old-provider new-provider
  ```
- **`-ignore-remote-version`**

  Ignore remote state version constraints when performing the operation.
  ```shell
  atmos terraform state replace-provider vpc -s dev -ignore-remote-version old-provider new-provider
  ```

## See Also

- [`atmos terraform state`](/cli/commands/terraform/state) - State management overview
- [`atmos terraform state mv`](/cli/commands/terraform/state/mv) - Move an item in the state
- [`atmos terraform state list`](/cli/commands/terraform/state/list) - List resources in the state
