Skip to content
SHC Docs

Destroy

A tofu destroy takes each shc_node out of the cluster before its machine is deleted, and a node that still carries deployments refuses to go. That refusal names the deployments in the way, and it is the right answer for a node you are retiring from a cluster that lives on. alice is refused the same way, as the last manager of prod. For a whole-cluster teardown you state the intent once: on_destroy = "force" on every node and on alice. It is read from state, so apply it before the destroy.

~/learn/cluster/terraform.tfvars
home_region = "nbg1"
far_region = "hel1"
home_count = 4
server_type = "cx23"
shc_version = "0.1.3"
on_destroy = "force"
work
$ tofu -chdir=learn/cluster plan
...
Plan: 0 to add, 6 to change, 0 to destroy.
...
$ tofu -chdir=learn/cluster apply -auto-approve
...
Apply complete! Resources: 0 added, 6 changed, 0 destroyed.
...

Now destroy. The order is the reverse of the applies: the record, the connection and the deployments go first, then the nodes leave the cluster, then Hetzner deletes the machines, the firewalls, the network and the key. The depends_on = [module.shc] lines of pages 04 and 05 hold that order: without them a node can leave while a deployment on it is still being removed, and that uninstall has nowhere to run.

work
$ tofu -chdir=learn/cluster destroy -auto-approve
...
$ tofu -chdir=learn/cluster state list

The state is empty. Ask Hetzner directly: every resource the module made carried the label cluster=learn, and none is left.

work
$ curl -s -H "Authorization: Bearer $HCLOUD_TOKEN" "https://api.hetzner.cloud/v1/servers?label_selector=cluster=learn"
{
"servers": [],
"meta": {
"pagination": {
"last_page": 1,
"next_page": null,
"page": 1,
"per_page": 25,
"previous_page": null,
"total_entries": 0
}
}
}
$ curl -s -H "Authorization: Bearer $HCLOUD_TOKEN" "https://api.hetzner.cloud/v1/networks?label_selector=cluster=learn"
{
"meta": {
"pagination": {
"last_page": 1,
"next_page": null,
"page": 1,
"per_page": 25,
"previous_page": null,
"total_entries": 0
}
},
"networks": []
}
$ curl -s -H "Authorization: Bearer $HCLOUD_TOKEN" "https://api.hetzner.cloud/v1/firewalls?label_selector=cluster=learn"
{
"firewalls": [],
"meta": {
"pagination": {
"last_page": 1,
"next_page": null,
"page": 1,
"per_page": 25,
"previous_page": null,
"total_entries": 0
}
}
}
$ curl -s -H "Authorization: Bearer $HCLOUD_TOKEN" "https://api.hetzner.cloud/v1/ssh_keys?label_selector=cluster=learn"
{
"ssh_keys": [],
"meta": {
"pagination": {
"last_page": 1,
"next_page": null,
"page": 1,
"per_page": 25,
"previous_page": null,
"total_entries": 0
}
}
}

The DNS record went with the cluster. Neither the name nor the ownership TXT managed DNS wrote beside it resolves any more:

work
$ dig +short tf.$TF_VAR_dns_zone
$ dig +short TXT _shc-owner.tf.$TF_VAR_dns_zone

The licence token on work and the state file’s history are yours to keep or shred; the state file still holds the retired vault password and the SSH key.

The host keys in learn/cluster/ssh/known_hosts belonged to the deleted machines, and the destroy does not remove that file. Hetzner can give a new machine an address an old one had, and SSH then refuses it as a changed host. Remove the file.

work
$ rm -f learn/cluster/ssh/known_hosts

The ladder is done. The same root module, with the count and the version changed back, builds the cluster again from nothing. The pages after this one each take another example root from terraform/examples and show what differs from the Hetzner front door you wrote.

Next: The hetzner-shc example.