gcloud compute instances delete: Tear Down a VM
gcloud compute instances delete permanently removes one or more VMs and, by default, their boot disks.
Ephemeral runners must be cleaned up or they keep billing. This is the teardown half of the create/delete pair, and the --quiet flag is what keeps it from hanging.
What it does
gcloud compute instances delete stops and deletes the named instances in a zone. By default it also deletes auto-created boot disks; --keep-disks lets you retain them. Deletion is irreversible.
Common usage
gcloud compute instances delete runner-1 \
--zone=us-central1-a --quiet
# delete several and keep their data disks
gcloud compute instances delete runner-1 runner-2 \
--zone=us-central1-a --keep-disks=data --quietFlags
| Flag | What it does |
|---|---|
| --zone <zone> | Zone the instance lives in |
| --quiet | Skip the "do you want to continue?" prompt |
| --keep-disks <type> | Keep disks of the given type (all, boot, data) |
| --delete-disks <type> | Force-delete disks of the given type |
In CI
Run delete in an always() / post step so it fires even when the job failed, and always pass --quiet because the default deletion prompt blocks on stdin and the job will time out without it.
Common errors in CI
"The resource ... was not found" usually means the instance is in a different zone than the one you passed, or it was already deleted. A job that hangs at "The following instances will be deleted" omitted --quiet. "Required 'compute.instances.delete' permission" means the runner identity lacks instanceAdmin rights.