Declare, plan, apply
Terraform
Terraform compares what you declared against what it recorded and proposes the difference. The state file is the memory of that comparison — lose it and you are adopting resources by hand.
The plan is the review
`init` downloads providers and writes the lock file; `plan` shows what would change without touching anything; `apply` performs exactly that. Read the plan for the lines you did not expect — a surprise `destroy` is the whole risk of the tool.
Provider and resource blocks are data, not code. There is no hidden step: what `apply` creates is what the files describe, plus whatever the provider defaults to.
State is the truth Terraform remembers
State maps your resource names to real ids. Without it, Terraform cannot tell whether the instance already exists — so deleting state does not delete infrastructure, it orphans it.
For anything shared, keep state remote and locked: two applies against the same local file will corrupt it, and the corruption is silent until the next plan.
Commands in this lesson
Every one of these runs in the sandbox — no real account, no real bill.
| Command | Why |
|---|---|
terraform init | Fetch providers and create the lock file. Nothing applies before this. |
terraform plan | The diff you review. Expected output is part of the change. |
terraform apply -auto-approve | Perform the plan. In the sandbox approval is automatic; in production it should not be. |
terraform output | The values your other tooling consumes — read them, do not recompute them. |
terraform state list | What Terraform believes it owns. The first thing to check when reality disagrees. |
Now do it
Reading the model makes the first attempt faster. Only the lab makes you able to do it.
- Open the lab
Provision Infrastructure with Terraform
Beginner · 30 min · members
- Open the lab
Variables, Outputs and count
Intermediate · 35 min · members
- Open the lab
Reuse a Local Module
Advanced · 40 min · members
Terraform · OphirCloud Academy · all lessons