# atmos terraform destroy

Use this command to destroy Terraform-managed infrastructure for an Atmos component in a stack. This operation removes all resources managed by the component.

_\[Video: atmos terraform destroy]_

## Usage

Execute the `terraform destroy` command like this:

```shell
atmos terraform destroy <component> -s <stack> [options]
```

This command creates a plan to destroy all resources managed by the given configuration and state, and then applies that plan.

:::info Atmos Enhancements
Atmos enhances the destroy command with:

- Automatic `terraform init` before destroying
- Workspace selection and management
- **Automatic variable file generation and passing**
- Backend configuration
- Component validation and locking support
  :::

## Configuration

Configure default behavior for `terraform destroy` in your `atmos.yaml`:

```yaml
components:
  terraform:
    # Auto-generate backend configuration
    auto_generate_backend_file: true
```

These settings can also be controlled via environment variables:

```shell
export ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE=true
```

## Examples

### Basic Destroy

```shell
# Destroy a component in a stack (will prompt for confirmation)
atmos terraform destroy vpc -s dev
```

### Auto-Approve Destroy

```shell
# Destroy without confirmation prompt (use with caution!)
atmos terraform destroy vpc -s dev -auto-approve
```

### Targeted Destroy

```shell
# Destroy specific resources only
atmos terraform destroy vpc -s dev -target=aws_instance.web
```

### Graph-backed Bulk Destroy

Run destroys for multiple components through the Terraform dependency graph:

```shell
# Destroy every Terraform component, with dependents before dependencies
atmos terraform destroy --all -s dev

# Destroy only selected components
atmos terraform destroy --components eks/apps,eks/cluster,vpc -s dev
```

Destroy reverses the dependency graph so dependents are destroyed before the components they depend on. For example, an application component is destroyed before its cluster, and the cluster is destroyed before the VPC.

Independent destroy nodes can run concurrently when `--max-concurrency` is greater than `1`. Concurrent destroy requires non-interactive approval with `-auto-approve`.

```shell
atmos terraform destroy --all -s dev --max-concurrency 2 -auto-approve
```

Use `--failure-mode keep-going` to continue independent graph branches after one component fails. The default is `fail-fast`.

## Arguments

- **`component` (required)**

  Atmos component name.

## Flags

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

  Atmos stack name where the component is defined.
- **`--skip-init` (optional)**

  Skip running `terraform init` before executing the command.
  ```shell
  atmos terraform destroy vpc -s dev --skip-init
  ```
- **`--dry-run` (optional)**

  Show what would be executed without actually running the command.
  ```shell
  atmos terraform destroy vpc -s dev --dry-run
  ```
- **`--log-order` (optional)**

  Controls how concurrent per-component logs are ordered when `--max-concurrency` is greater than `1`.

  Supported values:
  - `stream` _(default)_ — print log lines as they arrive, interleaved across components
  - `grouped` — buffer each component's output and print it as a contiguous block after the component finishes
  **Environment variable:** `ATMOS_TERRAFORM_DESTROY_LOG_ORDER`
  ```shell
  atmos terraform destroy --all -s dev --max-concurrency 2 -auto-approve --log-order grouped
  ```

## Native Terraform Flags

- **`-auto-approve`**

  Skip interactive approval before destroying.
  ```shell
  atmos terraform destroy vpc -s dev -auto-approve
  ```
  :::warning
  Use `-auto-approve` with extreme caution, especially in production environments.
  :::
- **`-target=RESOURCE`**

  Destroy only the specified resource. Can be used multiple times.
  ```shell
  atmos terraform destroy vpc -s dev -target=aws_instance.web -target=aws_instance.db
  ```
- **`-parallelism=N`**

  Limit the number of concurrent operations (default: 10).
  ```shell
  atmos terraform destroy vpc -s dev -parallelism=5
  ```

## Related Commands

- [`atmos terraform plan`](/cli/commands/terraform/plan) - Generate execution plan
- [`atmos terraform apply`](/cli/commands/terraform/apply) - Apply changes
- [`atmos terraform init`](/cli/commands/terraform/init) - Initialize working directory
