# Removing Stacks

If you ever need to delete a Quilt stack from your AWS account, you should know that:

* Your data in S3 buckets remains accessible.
* You can continue using the Quilt SDK for reading and writing packages.
* Stack-managed resources (Athena tables, Postgres database, audit logs) will be affected.
* The deletion behavior varies between CloudFormation and Terraform deployments.

***

### I. Impact Assessment and Preparation

#### What May Be Deleted

* Custom configurations specific to the Quilt stack (e.g., IAM roles, resource mappings, permissions).
* Analytics data in stack-managed buckets.
* Audit logs and Athena querying setups.
* User account and tabulator configurations.

#### Recommended Actions

* Export analytics data you need to keep.
* Save important audit logs.
* Document existing Athena configurations if you'll need to recreate them.
* Export the Postgres database (containing, e.g., user accounts and tabulator configuration) in case you want to reuse it for future stacks.

***

### II. Stack Deletion Process

#### Using CloudFormation

1. **Start the Deletion Process**
   * Navigate to the **CloudFormation** console in your AWS region.
   * Select your stack under **CloudFormation > Stacks**.
   * Click **Delete Stack** to begin the process.
2. **Empty or Ignore Non-Deleted Resources**
   * CloudFormation attempts to delete all stack-managed resources.
   * If a resource cannot be deleted (e.g., non-empty S3 bucket):
     * It will show a **DELETE\_FAILED** status in the **Events** tab.
     * Failed resources remain intact, including non-empty S3 buckets.
     * Other independent resources will still be deleted.
     * The stack enters the **DELETE\_FAILED** state.
   * If you wish to remove those resources:
     * Back up any important files.
     * Remove all files from the bucket via the S3 console or CLI.
     * Retry the deletion process.
   * Alternatively, you can leave them undeleted, though that may require manual cleanup later.

#### Using Terraform

1. **Start the Deletion Process**
   * Open a terminal in your Terraform configuration directory.
   * Run `terraform destroy`.
2. **Empty or Retain Non-Deleted Resources**
   * Terraform stops at the first resource it cannot delete (e.g., non-empty S3 buckets created by CloudFormation).
   * Dependencies of the failed resource are preserved.
   * To resolve, back up important files and clear the bucket contents.
   * Once addressed, resume deletion by re-running `terraform destroy`.

***

### III. Final Steps

* Verify deletion of all non-retained resources.
* Confirm that the stack is no longer listed in CloudFormation or Terraform.
* Check for any orphaned resources or residual costs using the **AWS Cost Explorer**.

***

### IV. After Stack Deletion

* Your S3 bucket data remains intact and accessible.
* The Quilt SDK continues to function for package operations.
* Recreate any necessary Athena/Glue configurations if needed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.quilt.bio/quilt-platform-catalog-user/advanced/removingstacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
