# Delete an app

Delete an app with everything it created, and know which two things are kept.

The platform nameservers stop answering for the app's names at once, and any deployment in flight
is marked failed with `The app was deleted`. A background job then removes everything the app
created: its machines, its load balancer and certificates, the IAM user its machines sign in with
with its access keys and policies, the DNS records pointing at it, its database and cache bindings,
and the registry repository that was created for it. The app, with its deployment history and
environment, goes last. A custom domain at another DNS provider keeps its record until you remove
it.

**Important:**
Deleting an app cannot be undone. Data in named volumes on its machines goes with the machines.

## Prerequisites

- Permission for `deploy:DeleteApp` on the app.
- In the console, also `deploy:DescribeApp` to open the app's page (without it the page is not
  found).

## Delete the app

**Console**
1. Open the app, then choose the **Danger zone** tab. Under **Delete this app**, **Container
   images** lists each registry repository the app touched and whether it is deleted or kept.
2. Choose **Delete app**. Without `deploy:DeleteApp` the button is unavailable and says why.
3. In **Delete <name>?**, enter the app's name, then confirm. The console returns to the app list.

**CLI**
```sh
dcloud deploy apps delete app-id --yes
```

Replace app-id with the app's id. Without `--yes` the CLI asks for confirmation, and
refuses when there is nobody to ask.

**API**
`DELETE /deploy/api/apps/app-id` answers `202` with `status: "deleting"`.

**Terraform**
Remove the `dcloud_app` resource from the configuration and run `terraform apply`, or run
`terraform destroy -target=dcloud_app.web`.

## What is kept

The app's activity says what is kept:

- A database role a binding created, with the data it owns, and the role's password in Secrets
  (it goes when the database is deleted). Drop the role from the database if you no longer need
  it.
- A registry repository, unless all of these hold: the app created it, no other app deploys from
  it, and every tag in it points at an image one of the app's deployments ran. A repository you
  created, or one CI or a person also pushed to (a `latest` tag from a workflow, say), keeps every
  image; it stops belonging to the app.

## Result

The app shows as deleting until everything is removed, then disappears. If something cannot be
removed, the app stays in `deleting` and its page says what is left and why; the job retries on its own, and
**Delete again** (or deleting the app again) retries at once.

## Related

- [Bind a managed database](bind-a-database.md)
- `deploy.apps.delete` · `dcloud deploy apps delete` · `dcloud_app`
