← Lessons/Your First Resource

Your First Resource

Time to actually write Terraform. You'll declare one resource, preview it with plan, create it with apply, and then read the state Terraform recorded.

Each mini lesson builds on the state the one before it left, so they unlock in order: the apply needs the resource you planned, and reading the state needs the apply.

hclresourcesstateplan

Interview prep

L2 covers two questions that come up in almost every Terraform interview.

What's the difference between plan and apply?

plan is a read-only preview: it diffs your desired config against state and the real world and shows what would change. apply actually makes those changes and updates state. You always plan first so there are no surprises.

What is Terraform state and why does it matter?

State is Terraform's record of the real resources it manages — the mapping from your config to real-world IDs. It's how Terraform knows what already exists, so a re-apply with no changes is a no-op (idempotency). Lose or corrupt it and Terraform no longer knows what it owns.