# Delete a secret

Delete a secret with every version, grant and access log entry, one at a time or many at once.

**Warning:**
Every version is deleted and cannot be recovered. An app variable bound to the secret is left
without a value: from the next rollout the app runs without that variable. A workflow job that
names it fails at its next run (in GitHub Actions syntax it gets an empty value), unless the
Default secret of that name remains to take its place.

Replace _5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e_ with the secret's id.

## Prerequisites

- Permission for `secrets:DeleteSecret` on the secret. In the console, also `secrets:ListSecrets`
  to open **Secrets**; without it the page says "You do not have permission to list secrets."
- Not a source's credential: disconnect the source instead (see [Manage a source](manage-a-source.md)).
- For a secret managed by Error Tracking: no app or CI environment uses it any more.

## Delete one secret

**Console**
1. Open **Secrets** and choose the secret.
2. In its panel, under **Danger zone**, choose **Delete secret**.
3. Enter the secret's name, then choose **Delete secret**.

**CLI**
```sh
dcloud secrets secrets delete 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e
```

**API**
```http
DELETE /secrets/api/secrets/5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e
```

**Terraform**
Remove the `dcloud_secret` resource and run `terraform apply`.

The answer is `200` with the deleted secret's `id`. Only this environment's secret of the name is
deleted.

## Delete many secrets

**Console**
1. Open **Secrets** and select the secrets' check boxes.
2. Choose **Delete**.
3. Enter the confirmation the dialog asks for (`delete 3 secrets` for three), then choose **Delete**.

**CLI**
```sh
dcloud secrets secrets bulk-delete --ids 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e
```

**API**
```http
POST /secrets/api/secrets/bulk/delete
{ "ids": ["5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e"] }
```

**Terraform:** not available. Remove each `dcloud_secret`.

At most 500 ids per call. Each is answered on its own in `{ results, succeeded, failed }`; the call
is not atomic.

## Refusals

- `409` "This is the credential of the secret source "_name_". Disconnect the source instead". In a
  bulk delete, that item fails with "The credential of the source "_name_". Disconnect the source
  instead".
- `409` for a secret managed by Error Tracking that an app or CI environment still uses, naming
  where to disconnect it.
- `403` without `secrets:DeleteSecret`.

## Related

- `secrets.secrets.delete` · `secrets.secrets.bulk-delete` · `dcloud_secret`
