# Build and destroy a stack per service, part 4: Spacelift, break and defend, and the claims register Part 4 of 4 of [Build and destroy a bunch: one stack per service](Build-and-Destroy-Stack-Per-Service.md): The Spacelift option, build, break, detect, evade, defend, common mistakes and the claims register. Previous: [Exercises 5 to 8 and the cloud lab](Build-and-Destroy-Stack-Per-Service-Part-3-Exercises-5-to-8-and-the-Cloud-Lab.md) > Unfamiliar word or acronym? The [Glossary](Glossary.md) defines it. > **Status: the free lab was run on Linux; the cloud lab was only validated, never applied; PowerShell was not run.** On **2026-10-22** the author ran the whole free lab on Linux with OpenTofu 1.12.6 (the version CI pins) and the `hashicorp/local` provider 2.9.1: five full build-and-destroy cycles, each ending with a checker that found every state empty, plus the wrong-order and forgotten-resource exercises ([Exercise 5](Build-and-Destroy-Stack-Per-Service-Part-3-Exercises-5-to-8-and-the-Cloud-Lab.md#exercise-5-destroy-in-the-wrong-order-on-purpose) and [Exercise 6](Build-and-Destroy-Stack-Per-Service-Part-3-Exercises-5-to-8-and-the-Cloud-Lab.md#exercise-6-a-forgotten-resource-and-an-untagged-one)); the output shown is from that run, trimmed. The cloud lab's five stacks were checked with `tofu init` and `tofu validate` against the `digitalocean/digitalocean` provider 2.106.0 (a schema check: no token, no API call, nothing created), so their argument names are right, but **nothing in them was ever applied**. Expect to fix something. The PowerShell scripts were written from Microsoft's and OpenTofu's documentation and **were not run** (there was no Windows machine): treat every PowerShell line as **est.** Vendor facts come from the pages listed in the [claims register](#claims-register), read on **2026-10-22**. Nothing here was run against this project's own stacks, which are locked. > **Prerequisites.** The three earlier lessons of the track: [OpenTofu from zero](OpenTofu-From-Zero.md) (init, plan, apply, destroy), [Plans, state, drift and recovery](Plans-State-Drift-and-Recovery.md) and [Spacelift from zero](Spacelift-From-Zero.md). If you want less first, [What is infrastructure as code](What-Is-Infrastructure-as-Code.md) and [OpenTofu, stacks and modules](OpenTofu-Stacks-and-Modules.md) cover the minimum (provider, resource, plan, apply, state, stack). Also useful: [The terminal and your first script](Terminal-and-Your-First-Script.md) and [Teardown checklist](Teardown-Checklist.md). The free lab needs OpenTofu 1.8 or newer, a terminal and a few megabytes of disk; no account, no money. About 60 minutes of reading and 90 minutes for the free lab (est.); the optional cloud lab adds about an hour (est.) and uses your own account. ## Optional: run the same stacks through Spacelift The same five stacks, with the dependencies as Spacelift stack dependencies and the outputs mapped to `TF_VAR_` variables, run through Spacelift's plan, approve and apply steps instead of from your terminal. That is the third lesson of the track: [Spacelift from zero](Spacelift-From-Zero.md). Read it for the setup. Do not point this project's own Spacelift stacks at any of it: those stacks are locked and only the maintainer changes them. ## Build, break, detect, evade, defend The same loop as the [labs](Labs-Break-It-on-Purpose.md), applied to a resource nobody remembers. Everything is in the free lab or on paper; you need no account. **Build.** The five-stack lab: every file tagged `cah-lab`, every stack destroyable, a checker that proves emptiness two ways. **Break.** A forgotten resource: a destroy that stops early, leaving `40-server-b` built. In a cloud this is a droplet nobody is looking at, billing every hour. You did it in Exercise 6. **Detect.** A tag audit. `grep -l '^tag=cah-lab$' world/*` in the lab; `doctl compute droplet list --tag-name ` in the cloud. It finds the forgotten stack and the tagged files, and a scheduled run of it, with a person who gets the result, turns "I should check" into a habit. Detection also has a second source: the billing page and cost analysis, which show spend by product whether or not you remembered the resource. That is why the teardown checklist insists on looking again the next day. **Evade.** A resource that does not carry the tag: `handmade.txt`. In a cloud it is a droplet made in the console, a resource whose provider does not support tags, a resource a script created with a typo in the tag, or a resource somebody deliberately left untagged. The tag audit does not find it. This is not an attack technique in any sense that needs a target; it is the ordinary way a clean-looking account is not clean, and an attacker who creates infrastructure in an account they have taken over has the same preference for not carrying your tags. Nothing here shows how to do that to anyone else's account. **Defend.** Four layers, none sufficient alone. - **Make untagged creation hard.** Where the platform has an organization-wide tag policy or a policy-as-code check, require the tag at creation (check whether your provider offers one; I did not verify DigitalOcean here, est.). In this project the equivalent is CI: the cost gate refuses a stack with no manifest and an unpriced billable resource type, and the plan policy refuses to delete a protected resource. - **Inventory the whole account, not only the tag.** List everything and explain each line. The lab's `audit.sh` does this for the folder. For a cloud account, the read-only listings in [Teardown checklist](Teardown-Checklist.md#3-prove-zero-billable-resources). - **A cost report and a spend alert,** read by a person. The report shows spend by product and by day; the alert tells you when you cross a line. Neither is a cap. - **Separate accounts for experiments,** so there is a small, known set of things that can be wrong. ### Flip the board Now be the person who has to run an account for a team, not the person who made one mistake. 1. You inherit an account with 60 resources and no stack for 20 of them. What is the first read-only thing you do, and what do you not do until you have it? 2. A teammate says "just tag it by hand afterwards." What is the argument against, and what is the argument for? 3. Production's network stack and a service's stack are both yours. Which one may a new hire destroy, and which approvals does the other need? 4. A cost report shows $40 for a product nobody on the team uses. Walk through finding the resource without clicking around: which listing, which filter, and which token scope? 5. Your destroy script reported success. Name three independent places you would look before you believed it. Write your answers down. Question 5 has the answer in [lessons-learned item 8](Build-and-Destroy-Stack-Per-Service-Part-1-Why-and-How-Stacks-Are-Split-and-the-Lab-Script.md#lessons-learned-what-makes-a-destroy-fail-or-leave-a-bill): resource listings, the provider's console, and tomorrow's billing page. ## Common mistakes | Symptom | Most likely cause | What to check | |---|---|---| | `Unsupported attribute` or `Error in function call` on a destroy of a consumer | The producer was destroyed first | Rebuild the producer, then destroy consumers first (Exercise 5). | | `No such file` or an empty output on the first plan of a consumer | The producer was never applied | Build in order. | | `Error: Failed to load plugin schemas` or provider download fails | No network to the registry, or a stale cache | Run `tofu init` again; set `TF_PLUGIN_CACHE_DIR` to a folder you own. | | The checker passes but the cloud still bills | The checker listed the wrong account, region or tag | Check the token's account, list without filters, look at the billing page tomorrow. | | `proof.sh` says "the listing FAILED" | `doctl` not installed, not logged in, or a token without read scope | Fix the credential; do not read a failed listing as zero. | | The loop stops at cycle 3 | A real failure, not noise | Read the first `Error` line; fix it; start the loop again from cycle 1. | ## Claims register All reads were read-only requests on **2026-10-22** unless a different date is shown. | Claim | Source | Status | |---|---|---| | Bundled-plan CPU droplets are billed per second, minimum 60 seconds or $0.01 (whichever is higher), usage capped at 672 hours (28 days) a month; billing starts at create and ends at destroy; powered-off bundled droplets are still billed because compute stays reserved | [Droplet pricing](https://docs.digitalocean.com/products/droplets/details/pricing/) (page marked "Last verified 25 Aug 2026") | Read | | The hourly rate of `s-1vcpu-512mb-10gb` | Not read from any vendor page. The script divides the monthly price by 672 | **est.** | | `s-1vcpu-512mb-10gb` is $4 and `s-1vcpu-1gb` is $6 a month | `docs/cost-prices.json`, retrieved 2026-10-21 | Read in this repository. Availability of the $4 size is not recorded for `tor1` in `docs/cost.md` | | A spend alert budget "is not a spending cap" | [Spend alerts](https://docs.digitalocean.com/products/billing/billing-alerts/) ("Last verified 19 Oct 2026") | Read | | Destroying a droplet does not destroy its automated backups (they stay four weeks); snapshots, volumes and volume snapshots are only destroyed if selected | [Destroy a Droplet](https://docs.digitalocean.com/products/droplets/how-to/destroy/) ("Last verified 13 Jul 2026") | Read | | Tags are custom labels for droplets and other resources; cloud firewalls are free and block all traffic not expressly permitted | [Tag Droplets](https://docs.digitalocean.com/products/droplets/how-to/tag/) and [Create a firewall](https://docs.digitalocean.com/products/networking/firewalls/how-to/create/) | Read. Which resource types take tags: not checked, **est.** | | `doctl` flags used: `compute droplet list --tag-name --format --no-header`, `compute droplet delete --tag-name --force`, `compute tag list/delete`, `compute firewall list/delete`, `vpcs list/delete`, `compute volume list`, `compute snapshot list`, `compute reserved-ip list`, `compute size list`, `account get` | [doctl reference](https://docs.digitalocean.com/reference/doctl/reference/) pages for each (generated 15 Oct 2026, doctl v2.0.0) | Flag names read; never run (no `doctl` on the author's machine). `--force` on firewall, vpcs and tag delete not confirmed, **est.** | | `GET /v2/droplets?tag_name=` filters by tag and needs the `tag:read` scope | [DigitalOcean OpenAPI source](https://github.com/digitalocean/openapi/blob/main/specification/resources/droplets/droplets_list.yml) | Read; not called | | `terraform_remote_state` reads root module outputs, needs access to the entire state snapshot, and does not respect the sensitivity of the source state; publishing explicitly to a separate location is recommended | [OpenTofu: terraform_remote_state](https://opentofu.org/docs/language/state/remote-state-data/) | Read | | Local state is plain-text JSON; state may contain sensitive values | [OpenTofu: sensitive data in state](https://opentofu.org/docs/language/state/sensitive-data/) | Read | | Spacelift stack dependencies respect tracked runs only; output references use outputs of a successful run that included an apply and map to environment variables (`TF_VAR_` for OpenTofu); sensitive-output transfer must be enabled; dependencies do not manage creating or deleting stacks | [Spacelift stack dependencies](https://docs.spacelift.io/concepts/stack/stack-dependencies) | Read. Whether a destroy run is ordered by a dependency was **not tested** | | The lab behaves as shown (five cycles clean; the wrong-order error; the tag search missing an untagged file) | Run on Linux, OpenTofu 1.12.6, `hashicorp/local` 2.9.1, 2026-10-22 | Run | | The cloud stacks are valid for the provider's schema | `tofu validate` with `digitalocean/digitalocean` 2.106.0, 2026-10-22 | Validated; never planned or applied | | This project's stack layout, cost gate, golden addresses, destroy guard and stack-factory status | Files in this repository at the commit this page was written against | Read | | Everything PowerShell; WSL as a way to run the generator; tag policies on other providers | Written from documentation or general knowledge | **est.**, not verified | Not verified, plainly: the whole PowerShell track; the cloud path from start to finish (including whether a new droplet is covered by a tag-attached firewall from its first second, and whether the $4 size is offered to your account and region); `--force` on three `doctl` delete commands; which DigitalOcean resource types accept tags; whether an organization-wide tag policy exists on DigitalOcean; whether a Spacelift destroy run is ordered by stack dependencies. Next: [Teardown checklist](Teardown-Checklist.md), the project's own version of the destroy order and the proof, with the destroy guard in front of it.