# atmos aws cloudformation delete

Delete the CloudFormation stack for a component (`DeleteStack`), then stream
stack events until the stack is gone, ending with the stack's own
`DELETE_COMPLETE` event and a `Deleted stack` confirmation. Termination
protection is always respected — Atmos never disables it silently.

> ⚠️ Experimental

## Usage

```shell
atmos aws cloudformation delete <component> --stack <stack> [options]
```

```shell
atmos aws cloudformation delete vpc -s plat-ue2-dev
```

Skip the interactive confirmation prompt:

```shell
atmos aws cloudformation delete vpc -s plat-ue2-dev --auto-approve
```

Retry a `DELETE_FAILED` stack, retaining resources that could not be deleted:

```shell
atmos aws cloudformation delete vpc -s plat-ue2-dev --retain-resources=SecurityGroup,ManualDbSnapshot
```

Delete a stack protected by `termination_protection: true`:

```shell
atmos aws cloudformation delete vpc -s plat-ue2-dev --disable-termination-protection
```

Delete components filtered by tags or labels (composes with `--all`/`--affected` to narrow the selected set further):

```shell
atmos aws cloudformation delete --all --tags production,tier-1
atmos aws cloudformation delete --affected --labels cost-center=platform
```

## Behavior

- A stack that does not exist is not an error. `delete` prints `<stack> does not exist; nothing to delete` and exits 0, the same way with or without a terminal, and also with `--retain-resources` or `--disable-termination-protection`.
- A stack protected by termination protection is refused with a "termination protection enabled" error and a hint to pass `--disable-termination-protection`.
- `--retain-resources` on a stack that is not in `DELETE_FAILED` is refused with its own error before anything is deleted.
- A delete that ends in `DELETE_FAILED` fails with a hint that names the resources CloudFormation could not delete and shows the retry: `delete <component> -s <stack> --retain-resources=<ids>`.

## Flags

- **`--stack`, `-s` (required for a single component)**
  Atmos stack. Required when operating on a single component; optional (and used only to narrow the selected set) with 
  `--all`
  /
  `--affected`
  .
- **`--auto-approve` (optional)**
  Skip the interactive confirmation prompt. Without it, 
  `delete`
   prompts for confirmation on a TTY before deleting the stack.
- **`--retain-resources` (optional)**
  Comma-separated logical IDs of resources to retain. Only valid when the stack is in 
  `DELETE_FAILED`
   status — CloudFormation rejects it otherwise.
- **`--disable-termination-protection` (optional)**

  Disable termination protection before deleting. If the component's
  `termination_protection` is `true`, `delete` fails with an actionable hint
  instead of silently disabling protection — pass this flag as an explicit
  escape hatch. Setting `termination_protection: false` in the stack
  configuration and re-applying does not disable protection: apply only
  ever turns protection on, never off.

:::note
`delete` fires the `before.aws/cloudformation.delete`/`after.aws/cloudformation.delete` hook events.
:::
