> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fjall.io/llms.txt
> Use this file to discover all available pages before exploring further.

# fjall destroy

> Destroy Fjall organisation infrastructure or applications and tear down their AWS resources in dependency order.

<Warning>
  **Destructive command.** This permanently deletes AWS resources. Back up data first.
</Warning>

## Overview

`fjall destroy` removes AWS resources created by Fjall. It handles organisation-level teardown and application teardown, removing resources in the correct dependency order.

## Usage

```bash theme={null}
fjall destroy [target] [options]
```

## Destruction Types

### Organisation Destruction

Remove AWS organisation infrastructure:

```bash theme={null}
fjall destroy organisation
```

This removes:

* Identity Centre configuration
* Account references

By default, destroying the organisation cascades to the platform and every member account. Pass `--no-cascade` to destroy only the organisation stack.

### Platform Destruction

Remove platform infrastructure:

```bash theme={null}
fjall destroy platform
```

This removes:

* IPAM pools
* Shared networking

### Account Destruction

Remove per-account foundation resources:

```bash theme={null}
fjall destroy account
```

This removes:

* CloudTrail trails
* EventBridge rules
* ECR repositories
* Backup vaults

### Application Destruction

Remove a specific application:

```bash theme={null}
fjall destroy api
```

This removes:

* Load balancers
* Application services (ECS, Lambda)
* Databases (after confirmation)
* Networking resources
* Security groups

## Interactive Mode

Run without arguments for guided destruction:

```bash theme={null}
fjall destroy
```

Fjall asks what to destroy, then which target, then confirms:

```bash theme={null}
? What would you like to destroy?
  ❯ Application      Remove cloud applications
    Organisation     Remove AWS foundation

? Select application to destroy:
  ❯ Api
    Web
    Dashboard

⚠️  This will destroy all resources for 'api'
? Are you sure? (y/N)
```

Choosing **Organisation** opens a second picker (organisation, platform, or account). Selecting **organisation** then asks whether to cascade to the platform and every member account.

## Options

| Option                | Description                                            | Example                             |
| --------------------- | ------------------------------------------------------ | ----------------------------------- |
| `-v, --verbose`       | Show detailed destruction logs                         | `fjall destroy -v`                  |
| `-f, --force`         | Auto-confirm destruction (required in non-interactive) | `fjall destroy --force`             |
| `--no-cascade`        | Skip automatic platform/account destruction            | `fjall destroy --no-cascade`        |
| `--skip-confirmation` | Skip destruction confirmation prompts                  | `fjall destroy --skip-confirmation` |
| `--non-interactive`   | Disable all prompts                                    | `fjall destroy --non-interactive`   |

## Arguments

The destroy command accepts a positional argument for specifying the target:

```bash theme={null}
fjall destroy [target]
```

| Argument | Description                                                | Example             |
| -------- | ---------------------------------------------------------- | ------------------- |
| `target` | Application name, or `organisation`, `platform`, `account` | `fjall destroy api` |

## Aliases

`destroy` has one alias, `delete`:

```bash theme={null}
fjall delete api    # Same as fjall destroy api
```

<Warning>
  `fjall remove` is **not** a destroy alias. It is the codemod command that removes a single resource from an application's `infrastructure.ts` source file. It does not delete any deployed AWS resources. See [fjall add](/cli/add) for the codemod engine.
</Warning>

## Destruction Process

### 1. Pre-destruction Checks

Fjall validates:

* AWS credentials are valid
* Target exists
* No dependent resources exist
* Data backup requirements

### 2. Resource Analysis

For each target:

* Lists all resources to be deleted
* Identifies dependencies
* Checks for data that needs backup
* Calculates destruction order

### 3. Confirmation

```bash theme={null}
🗑️  Preparing to destroy api...

Resources to delete:
  - AWS::ElasticLoadBalancingV2::LoadBalancer
  - AWS::ECS::Service (ApiService)
  - AWS::ECS::Cluster (ApiCluster)
  - AWS::RDS::DBCluster (ApiDatabase)
  - AWS::EC2::SecurityGroup (3)
  - AWS::EC2::VPC

⚠️  This action cannot be undone!

Destroy? (y/N)
```

### 4. Destruction Execution

Fjall:

* Deletes resources in reverse dependency order
* Monitors CloudFormation stack deletion
* Handles errors gracefully
* Reports completion status

## Safety Features

### Confirmation Required

By default, Fjall requires explicit confirmation:

* Shows all resources to be deleted
* Warns about data loss
* Requires typing 'y' to proceed

### Cascade Control

Destroying the `organisation` target cascades to the platform and every member account by default. To destroy only the organisation stack, pass `--no-cascade`. The cascade confirmation prompt spells out exactly what will be removed before any deletion starts.

### Order of Destruction

Resources are removed safely:

1. Application services
2. Load balancers
3. Databases (with extra confirmation)
4. Network resources
5. Base infrastructure

## Examples

### Destroy Application

```bash theme={null}
# Interactive with confirmation
fjall destroy

# Direct with confirmation
fjall destroy api

# Skip all prompts (dangerous!)
fjall destroy api --force --non-interactive
```

### Destroy Organisation Infrastructure

```bash theme={null}
# Destroy the organisation stack only
fjall destroy organisation --no-cascade

# Destroy organisation, platform, and all member accounts
fjall destroy organisation
```

### Verbose Destruction

```bash theme={null}
# See detailed progress
fjall destroy api --verbose
```

## Common Issues

### Resources Not Deleting

1. **Stack DELETE\_FAILED**

   ```bash theme={null}
   ❌ Stack deletion failed: Resource cannot be deleted
   ```

   **Fix**: Check CloudFormation console for specific resource blocking deletion

2. **Non-empty S3 Buckets**

   ```bash theme={null}
   ❌ S3 bucket must be empty before deletion
   ```

   **Fix**: Empty bucket manually or use AWS Console

3. **RDS Deletion Protection**
   ```bash theme={null}
   ❌ Database has deletion protection enabled
   ```
   **Fix**: Disable deletion protection in RDS console first

### Manual Cleanup

If automatic destruction fails:

1. **Check CloudFormation**: view specific errors
2. **Remove blockers**: empty S3 buckets, disable protections
3. **Retry destruction**: run the command again
4. **Manual deletion**: use the AWS Console as a last resort

## Best Practices

1. **Back up data first**: export databases before destruction
2. **Destroy non-production first**: test the teardown in staging
3. **Review resources**: run `fjall list -a api` to see what an application declares
4. **Use verbose mode**: add `-v` to see detailed progress

## Data Preservation

### Before Destroying Databases

1. **Create snapshots**:

   ```bash theme={null}
   # RDS/Aurora snapshots are automatic
   # Check AWS Console for snapshot creation
   ```

2. **Export data**:

   ```bash theme={null}
   # Use AWS tools to export if needed
   aws rds create-db-snapshot
   ```

3. **Verify backups**:
   * Check RDS snapshots exist
   * Confirm S3 bucket contents copied
   * Save any CloudWatch logs needed

After destruction, verify cleanup in the AWS Console and confirm billing for the torn-down resources has stopped.

<Note>
  CloudFormation stacks can take 5-10 minutes to delete completely. Monitor progress in the AWS Console if needed.
</Note>

## Next Steps

<CardGroup cols={2}>
  <Card title="fjall deploy" icon="rocket" href="/cli/deploy">
    Redeploy an application or organisation infrastructure.
  </Card>

  <Card title="fjall list" icon="list" href="/cli/list">
    Inspect the resources an application declares in infrastructure.ts.
  </Card>

  <Card title="fjall add" icon="plus" href="/cli/add">
    Edit infrastructure.ts with the codemod engine.
  </Card>

  <Card title="fjall restore" icon="clock-rotate-left" href="/cli/restore">
    Restore data from a snapshot after teardown.
  </Card>
</CardGroup>
