sn sysnerdunderstand it from the kernel up
← curriculum map
Terraform
Tool · ~50 min · 4 labs
map / The stack / Terraform
The stack Tool ~50 min requires: Kubernetes

Terraform

Terraform is the reconcile loop you saw in Kubernetes, applied to infrastructure: a desired-state file, a state file, and a diff engine. Understand state and Terraform stops surprising you. We use the local provider — no cloud, no cost.

Before you start. Install Terraform (or OpenTofu). Every lab here uses the local provider so nothing is provisioned in the cloud.
Q1Desired state and the planwarm-up

You declare what should exist; plan diffs that against reality and shows the delta before touching anything.

Task

Declare a local_file resource and plan it.

Verify it yourself
verify
$ terraform plan

The plan shows 1 to add — the gap between your desired state and the empty world.

Reveal solution
solution
$ cat > main.tf <<EOF
resource "local_file" "hello" {
  content  = "built by terraform"
  filename = "\${path.module}/out.txt"
}
EOF
$ terraform init
$ terraform plan
Q2Apply and inspect the state filecore

apply makes reality match desired state and records what it did in terraform.tfstate — Terraform's memory of the world.

Task

Apply, then look at the state.

Verify it yourself
verify
$ test -f out.txt && echo created

The file exists and terraform.tfstate (JSON) now records the resource. State is how Terraform knows what it owns.

Reveal solution
solution
$ terraform apply -auto-approve
$ cat out.txt
$ jq .resources[0].instances terraform.tfstate
Q3Drift — reality moves without youdebug

Change a managed resource by hand and Terraform notices: plan shows drift, apply reconciles it back.

Task

Edit the file outside Terraform, then plan.

Verify it yourself
verify
$ terraform plan

Plan reports the file changed and offers to restore it — desired-state reconciliation, exactly like a Kubernetes controller.

Reveal solution
solution
$ echo tampered > out.txt
$ terraform plan          # shows drift
$ terraform apply -auto-approve   # restores desired state
Sponsored

Reach engineers who read the man page

Native, contextual, no tracking — this is how the curriculum stays free.

Q4The dependency graphcore

When one resource references another, Terraform builds a DAG and orders operations correctly — the same kind of dependency graph this whole curriculum is organised by.

Task

Make one resource reference another and render the graph.

Verify it yourself
verify
$ terraform graph

The output shows an edge from the dependent resource to the one it references — Terraform figured out the order for you.

Reveal solution
solution
# add a second local_file whose content references local_file.hello.content
$ terraform graph | grep -i local_file
What you just built

Desired state, a state file, plan/apply, drift, a dependency DAG — Terraform is Kubernetes' reconcile idea for infrastructure. The mental model transfers directly; only the objects change.