# Spacelift from zero: your first stack, run and teardown > Unfamiliar word or acronym? The [Glossary](Glossary.md) defines it. **On this page:** - [Read this first: what this lesson touches, and what it never touches](#read-this-first-what-this-lesson-touches-and-what-it-never-touches) - [What you will be able to do](#what-you-will-be-able-to-do) - [What a hosted runner is, and the alternatives](#what-a-hosted-runner-is-and-the-alternatives) - [Plans, workers and limits, as read on 2026-10-22](#plans-workers-and-limits-as-read-on-2026-10-22) - [The pieces, in the order you meet them](#the-pieces-in-the-order-you-meet-them) - [Why this project's proposed-run check is red by design](#why-this-projects-proposed-run-check-is-red-by-design) - [Free theory path: build and run the scratch stacks on your own computer](#free-theory-path-build-and-run-the-scratch-stacks-on-your-own-computer) - [Optional: your own Spacelift account and scratch repository](#optional-your-own-spacelift-account-and-scratch-repository) - [Build and destroy a bunch](#build-and-destroy-a-bunch) - [Build, break, detect, evade, defend](#build-break-detect-evade-defend) - [Common mistakes](#common-mistakes) - [Checkpoint](#checkpoint) - [Claims register](#claims-register) - [Where to next](#where-to-next) Lesson I3 of the four-lesson infrastructure-as-code track. The track: I1 [OpenTofu from zero: init, plan, apply, destroy](OpenTofu-From-Zero.md), I2 [Plans, state, drift and recovery](Plans-State-Drift-and-Recovery.md), **I3 this page**, I4 [Build and destroy a stack per service](Build-and-Destroy-Stack-Per-Service.md). A foundations side page to [Spacelift](Spacelift.md); no step of the core path is renumbered. > **Status: written from vendor documentation; the free local exercises were run once, the Spacelift console exercises were not.** On **2026-10-22** the author read the Spacelift pricing and documentation pages listed in the [claims register](#claims-register) with read-only `curl`, and ran the free local exercises (Exercises 1 and 2) on Linux with OpenTofu 1.12.6, pasting trimmed output from that run. The own-account path (Exercises 3 to 11) uses menu names as the documentation gave them that day; **nobody has run it against a real Spacelift account for this page**, so every console step, every message it shows and every statement about what the free plan lets you do is marked **est.** unless the claims register says it was read. Vendor pages change; if your screen disagrees, trust your screen and the vendor's current page, and tell the project (see [Give feedback and open an issue](Give-Feedback-and-Open-an-Issue.md)). Windows PowerShell commands are **est.** (not run; no PowerShell was available when this was written). > **Prerequisites.** [OpenTofu from zero](OpenTofu-From-Zero.md) (I1) and [Plans, state, drift and recovery](Plans-State-Drift-and-Recovery.md) (I2), or the same ideas from [What is infrastructure as code](What-Is-Infrastructure-as-Code.md): plan, apply, state. [Git from zero](Git-From-Zero.md) for branches, commits and pushes, and [Git, GitHub and pull requests](Git-GitHub-and-Pull-Requests.md) for pull requests. A terminal ([The terminal and your first script](Terminal-and-Your-First-Script.md)). The free theory path needs no account. The own-account path needs a GitHub account and a Spacelift account, both yours. About 90 minutes for reading and the free local exercises (est.); the own-account path adds about three hours (est.), most of it waiting for runs and clicking. > **I1, I2 and I4 were written at the same time as this page by other authors.** This page does not depend on their text; it repeats the three words it needs (plan, apply, state) where it uses them. ## Read this first: what this lesson touches, and what it never touches - **It never touches the maintainer's Spacelift account or this repository's stacks.** This project runs `cah-00-foundation`, `cah-10-access` and `cah-20-telemetry` in the maintainer's own Spacelift account. They are **locked and manual on purpose**: deletion protection on, autodeploy off, a human confirms every apply. You do not need access to them for anything here, you cannot get it from this page, and you should never ask for it. Everything below happens in a Spacelift account **you** create, against a scratch GitHub repository **you** create. - **No cloud, no cloud bill.** The scratch stacks use only OpenTofu's built-in `terraform_data` resource, which records a value in state and creates nothing anywhere. There is no provider to download and no credential to hold. (The `random` and `local` providers are also free and need no cloud account, but they are downloaded from a public registry, so this page keeps to `terraform_data`.) - **Nothing here uses this project's tokens.** The project's secrets live in Doppler and reach its stacks through a hook ([Doppler and secrets](Doppler-and-Secrets.md)). Your scratch stacks need no secret of that kind. The one secret-shaped thing you will make is a throwaway value in a Spacelift environment variable, and you will build it at run time. - **This page names Spacelift because the project uses it.** It states no affiliation with Spacelift or any other vendor named here, and none is known. It is not an endorsement or a comparison test: other tools can do this job (next section). ## What you will be able to do - Say in plain words what a hosted infrastructure-as-code runner is, what Spacelift adds to `tofu plan` and `tofu apply`, and name the other kinds of tool that do a similar job. - State the plan limits that matter to a learner (what the free plan is said to include, what needs a higher plan, what needs a private worker) and say where you read them and when. - Connect a GitHub repository to Spacelift with the least access that works (one repository, not all of them). - Create a stack, point it at a project root, choose OpenTofu and a version, and explain what each setting does. - Tell a **proposed run** (a preview, triggered by a branch or pull request) from a **tracked run** (a deployment, triggered by a push to the tracked branch), walk through the phases of a run, and **confirm** or **discard** one. - Set an environment variable and a secret variable on a stack, explain what a context is, and say why this project keeps secrets in Doppler and not in Spacelift variables. - Read a plan policy and a push policy written in Rego, and say what each can and cannot stop. - Chain two stacks with a dependency and an output, and know why drift detection and scheduled runs sit behind a higher plan. - **Destroy before you delete, in the right order**, and prove nothing is left; then tear down the integration itself. - Run a build-and-destroy loop over several scratch stacks with a checklist that proves the account and the repository are empty at the end. ## What a hosted runner is, and the alternatives You already know the loop from I1: `tofu plan` shows what would change, `tofu apply` makes it so, and **state** is the file where OpenTofu remembers what it built. On your laptop all three live on one machine, under one person's credentials, and nobody else sees a plan before it applies. A **hosted runner** (Spacelift is one) moves that loop onto a service. You push code to Git; the service checks out the code on a **worker** (a container the service starts for the run), runs `tofu plan`, **holds the state** for you, shows the plan, **waits for a person to approve**, then applies. It also gives you history (who ran what, when), permissions, and a place to attach rules written as code. What that buys, in order of how much it matters to a beginner: 1. **A plan that someone reads before it applies.** The service stops after planning and shows the difference. 2. **Credentials in one place.** The cloud token is on the service, not on every laptop and in every CI job. 3. **State that is not on your laptop.** Lose the laptop, keep the state. 4. **A record.** Every run is listed, with its commit and who confirmed it. What it costs: a dependency on another company's service, a second place where access must be managed, and a new set of words. [Spacelift](Spacelift.md) explains why this project chose one; this page teaches you to use one. **Alternatives, named without a ranking.** None was tested for this page, and no price or limit for them was read. Other hosted services that run OpenTofu or Terraform include HCP Terraform (HashiCorp), env0 and Scalr. Self-managed options include Atlantis, which runs on a server you operate and comments on pull requests, and a plain CI system (GitHub Actions, GitLab CI) running `tofu` with a state bucket you provide. [Why I picked these tools](Why-I-Picked-These-Tools.md) is the project's reasoning; check each vendor's current terms yourself before you decide, because terms change. ## Plans, workers and limits, as read on 2026-10-22 Read from [spacelift.io/pricing](https://spacelift.io/pricing) with `curl` on **2026-10-22**: | What | What the page says | What it does not say | |---|---|---| | Free plan | "Always free for small teams. No credit card, no time limit." It includes 2 users and 1 public worker. | How many stacks, runs or run minutes it allows. Which features of the comparison table the free plan has: the table has no column for it. | | Higher plans | Starter+, Business, Enterprise and Enterprise+, by quote ("Request a quote"), no prices listed. | Any dollar figure. This page therefore states none. | | Public worker | Spacelift runs it in a shared pool; each run is its own isolated container. | | | Private worker | A worker you host in your own cloud; Starter+ and above. | | | Drift detection | Listed as included from Starter+ on the pricing page. | | Read from the documentation (`docs.spacelift.io`) on the same day: | Feature | Documentation says | Consequence for you | |---|---|---| | Policies (Rego) | "This feature is only available to paid Spacelift accounts." ([policy page](https://docs.spacelift.io/concepts/policy/)) | On the free plan you can read policies and test them on your own computer, but this page expects you cannot attach them. Confirm in the console. | | Drift detection | "Only available on the Starter+ plan and above." "Drift detection only works on private workers." ([drift page](https://docs.spacelift.io/concepts/stack/drift-detection)) | Read-only for you. | | Scheduling (scheduled tasks, scheduled runs, scheduled stack deletion) | "Only available on the Business plan and above." Schedules on public workers do not trigger. The page says nothing about running a single task by hand, so whether the free plan offers that is **unconfirmed**. ([scheduling page](https://docs.spacelift.io/concepts/stack/scheduling)) | Read-only for you. | | Targeted replan | "Only available to Business plan and above." | Not used. | | Stack dependencies, contexts | Documented with no plan note on their pages. The pricing comparison lists them but shows no Free column. | **Unconfirmed for the free plan.** Exercises 7 and 8 say what to do if your account lacks them. | | Audit trail | Listed under Enterprise on the pricing page. | Not available to you; the run list is your record. | Two honesty notes. First, the documentation's signup instruction says to click **Free trial** at the top right of the home page, and the pricing page's free-plan banner links to the same address, while the pricing page text calls the free plan "no time limit". Whether you get a time-limited trial of a higher plan or the free plan after signing up is **something to read on your own screen** (Exercise 3); if you are offered a card form, stop and read before you enter anything. Second, the product the documentation calls "Spacelift Deploy" is the same thing this project calls Spacelift; the documentation says the name changed when "Spacelift Flows" was added. This page uses "Spacelift". **Cost.** Per [docs/cost.md](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/cost.md), the project's own Spacelift wiring is a $0 line (stage 0). For your scratch account, the figure to hold is: **$0 if you stay on the free plan and enter no payment card; you control the card, so you control the bill.** A GitHub account and a scratch repository are free. No cloud resource exists, so no cloud bill can. ## The pieces, in the order you meet them Each paragraph names a Spacelift word, says what it is, and says what to look for. **Source control integration.** Spacelift needs to read your repository and report back on commits and pull requests. For GitHub that is a **GitHub App**: a small program GitHub lets you install on your account, with a list of permissions you can read before you accept. The documentation lists the permissions of the custom-app route: repository Checks, Commit statuses, Deployments, Pull requests and Webhooks at read and write; Contents and Metadata read-only; organization Members read-only. The point for you is the choice at install time: **all repositories or only selected ones.** Choose selected, and select the scratch repository only. That is least privilege: if the app, or Spacelift, is ever compromised, the damage stops at one disposable repository. **Stack.** The documentation defines it as source code, the current state of the managed infrastructure, and configuration (environment variables and mounted files), "an isolated, independent entity". One stack, one state. This project has one stack per directory under `stacks/`. A stack with no runs shows the state "None". **Project root.** The folder in the repository where the stack's code lives. It matters twice: it tells the worker where to run `tofu`, and it tells Spacelift which pushes affect this stack (per this project's [secrets runbook](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/spacelift-secrets.md), which read Spacelift's documentation on 2026-10-12, a push that changes only files outside the project root and outside the **project globs** you add does not start a run for it). Wrong project root is the most common first failure ("no configuration files"). **Vendor and version.** You choose OpenTofu (a dedicated vendor in the documentation) or Terraform (FOSS), and a version or a range such as `~> 1.10`. The documentation says the version is required and "latest" is rejected. The same page says that when you create a stack and choose **Manage State**, Spacelift holds the state, and that creation is the only time you can ask Spacelift to be the state backend ("This is the only time you can ask Spacelift to be the state backend for a given OpenTofu stack"). Leave it on for this lesson. This project's stacks use the Terraform vendor with the OpenTofu workflow tool; see [Spacelift](Spacelift.md#opentofu-inside-spacelift) for why. **Tracked branch.** The branch a stack deploys from, normally `main`. A push to it starts a **tracked run**; a push to any other branch starts a **proposed run**, by default. **Proposed run.** A preview. The documentation: "previews of changes that would be applied", triggered by Git push events to branches other than the tracked branch, for each affected stack. It runs the planning phase and stops. It reports in the pull request as a commit status and a comment. It never applies. **Tracked run.** A deployment: it plans, and if there are changes it can apply. Triggered by a person, by a push to the tracked branch, or by a trigger policy. If the plan shows no change, the run is a **no-op** and finishes without an approval step. **The phases.** In the order you will see them in the run view (the full list is on the [run page](https://docs.spacelift.io/concepts/run/)): | Phase | What happens | Passive? | |---|---|---| | Queued | Waiting for a worker or for another run to release the stack's lock. Only one run changes a stack's state at a time. | yes | | Preparing | Spacelift hands the job to a worker. | | | Initializing | The worker runs before-init hooks, then `tofu init`. | | | Planning | The worker runs `tofu plan`; plan policies (if any) are evaluated. | | | Unconfirmed | The plan is done and shows a change; nothing happens until a person acts. | yes | | Confirmed | A person accepted the plan; waiting for a worker. | yes | | Applying | The worker runs `tofu apply`. | | | Finished | Done. Also the end of a proposed run or a no-op. | terminal | | Discarded | A person rejected the plan, or an unconfirmed run waited too long. | terminal | | Failed | Something broke: bad code, a hook, a policy `deny`, an apply error. | terminal | "Passive" is the documentation's word for a state where "no operations are performed". Timeouts worth knowing: an unconfirmed run with no change for 7 days becomes discarded, and any run not finished in 30 days is closed by Spacelift (read from the run page, 2026-10-22). **Confirm and discard.** In the Unconfirmed state the run page shows the plan and two buttons. Confirm means "apply exactly this". Discard means "stop, change nothing". Autodeploy, when on, skips this step if there are no plan-policy warnings; that is why this project leaves it off ([Why autodeploy is off](Spacelift.md#why-autodeploy-is-off)). **Environment variables.** Set per stack, on its Environment tab. A variable named `TF_VAR_x` becomes the OpenTofu input variable `x`. You can mark a variable **secret**: its value is then hidden in the console and the API, and you cannot read it back, only replace it. **Contexts.** A context is a bundle of environment variables, mounted files and hooks, kept apart from any stack and attached to as many stacks as you like. The `autoattach: