# Delete a hosted zone

Delete a hosted zone with every record set and DNSSEC key in it.

Replace _zone-id_ with the id of the zone, and _example.com_ with its domain.

**Warning:**
A zone is removed at once and cannot be restored. Every record set goes with it, including the
`ALIAS` records the platform wrote for your apps' custom domains. If the domain still delegates to
the platform nameservers, it stops resolving: they answer `REFUSED` for it.

## Prerequisites

- Permission for `dns:DeleteZone`. Without it, **Delete zone** is unavailable, with the note "Your
  policies do not grant dns:DeleteZone on this zone; ask an administrator."
- In the console, also `dns:ListZones` to open **Hosted zones** (without it the page shows an
  access-denied notice) and `dns:GetZone` to open the zone (without it the zone's page is not
  found).
- If the domain should keep resolving: move it to another DNS host first, and change the
  nameservers at the registrar. Export the records to take them along (see
  [Import or export a zone file](import-or-export-a-zone-file.md)). If the zone is signed, remove
  its DS record at the registrar first (see [Turn off DNSSEC](turn-off-dnssec.md)).

## Delete the zone

**Console**
1. Open the zone, then choose the **Danger zone** tab (or, in the **⋯** menu, **Delete zone**).
2. Under **Delete this zone**, choose **Delete zone**.
3. In the dialog, enter example.com, then choose **Delete**.

The console returns to **Hosted zones**. If the delete fails, the reason appears under **Delete
this zone**, after "The zone was not deleted:".

**CLI**
```sh
dcloud dns zones delete zone-id
```

**API**
```http
DELETE /dns/api/zones/zone-id
```

The answer is `200` with the zone's `id`, or `404` "Zone not found".

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

## Result

The zone, its record sets, its DNSSEC keys and its query-logging setting are gone. The domain is
free again for anyone to host.

## Related

- [Create a hosted zone](create-a-hosted-zone.md)
- `dns.zones.delete` · `dcloud dns zones delete` · `dcloud_dns_zone`
