Date: 2026-05-11
Time: 15:36
A standalone teardown script that destroys a Linode cloud instance by looking up its label from a local state file and issuing a DELETE against the Linode API. It cleans up the state file afterward. This is the counterpart to a provisioning script that creates instances and writes state.json.
# Destroy using default state.json in current directory
LINODE_TOKEN=xxx ./destroy_linode.py
# Destroy using a custom state file
LINODE_TOKEN=xxx ./destroy_linode.py my-server-state.json
Runs as a uv run script — uv resolves the httpx dependency automatically, no venv setup needed.
| Input | Type | Description |
|-------|------|-------------|
| argv[1] | CLI arg (optional) | Path to state file. Defaults to state.json |
| LINODE_TOKEN | Env var (required) | Linode API personal access token |
State file format — expects JSON with a resources dict where each value has a "label" key:
{"resources": {"my_server": {"label": "my-linode-label"}}}
GET /linode/instances, not by stored instance ID. This means it scans the full instance list.next(iter(resources.values())) — only processes the first resource in the state file, ignoring any others.raiseforstatus() on both the list and delete calls — any HTTP error (auth failure, rate limit, server error) raises an unhandled exception.httpx to call GET /linode/instances and DELETE /linode/instances/{id}.httpx as its only dependency.