# 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`.

Use `--include-dependents` to tear down a selection plus everything that depends on it, dependents first:

```shell
# Destroy the vpc components and everything that depends on them, dependents first
atmos terraform destroy --components=vpc -s dev --include-dependents

# Bound the expansion to direct dependents only
atmos terraform destroy --components=vpc -s dev --include-dependents=1
```

:::warning
Using `--include-dependencies` with destroy also destroys the shared prerequisites of your selection — components that other, unselected components may still depend on. Atmos prints a warning when this flag is used with destroy. Prefer `--include-dependents`, which tears down the selection plus everything that depends on it, in safe dependents-first order.
:::

## 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
  ```
- **`--include-dependents` (optional)**

  With a multi-component selection (`--all`, `--components`, `--query`, `--stack`, `--tags`, `--labels`, `--affected`), also destroy everything that depends on the selected components, dependents first. Accepts an optional depth: the bare flag expands the full dependent chain, while `--include-dependents=1` bounds it to direct dependents. Pass the depth with `=`; a space-separated value is not bound to the flag.
  ```shell
  atmos terraform destroy --components=vpc -s dev --include-dependents
  ```
  **Environment variable:** `ATMOS_INCLUDE_DEPENDENTS`
- **`--include-dependencies` (optional)**

  With a multi-component selection, also destroy the prerequisites of the selected components — even prerequisites in other stacks. Because prerequisites may be shared with components outside the selection, Atmos warns when this flag is used with destroy; prefer `--include-dependents` for safe teardown. Accepts an optional depth (for example, `--include-dependencies=1` for direct dependencies only).
  ```shell
  atmos terraform destroy --components=eks/cluster -s dev --include-dependencies
  ```
  **Environment variable:** `ATMOS_INCLUDE_DEPENDENCIES`
- **`--ui` (optional)**

  Enable streaming UI mode for real-time resource destruction progress. Shows a Docker-build-style progress view with spinners, a resource dependency tree, and resource states.

  The UI automatically disables when output is piped, in CI environments, or when running unsupported commands.

  `--ui` errors when combined with `--max-concurrency` greater than `1`, since concurrently-scheduled components can't share one terminal for their full-screen UI sessions. Use `--max-concurrency 1` (the default) with `--ui`, or drop `--ui` to run concurrently.
  ```shell
  atmos terraform destroy vpc -s dev --ui
  ```
  Use `--ui=false` to explicitly disable when enabled by config.

## 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
  ```

### Default Locking and Concurrency Flags

Instead of retyping flags like `-lock-timeout` on every invocation, declare a default
in [`components.terraform.flags`](/cli/configuration/components/terraform#flags) — globally
in `atmos.yaml`, per stack, or per component. `destroy` supports all five flags
(`lock_timeout`, `lock`, `parallelism`, `refresh`, `compact_warnings`); a native flag typed
directly on the command line (as shown above) always wins over a declared default.

## 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
