OphirCloud Academy

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.

commitbuildtestdeploy→→→A red stage stops the next one — without anyone remembering to check.
The pipeline lives in the repository, so it is reviewed and versioned with the code it ships.

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.

CommandWhy
terraform initFetch providers and create the lock file. Nothing applies before this.
terraform planThe diff you review. Expected output is part of the change.
terraform apply -auto-approvePerform the plan. In the sandbox approval is automatic; in production it should not be.
terraform outputThe values your other tooling consumes — read them, do not recompute them.
terraform state listWhat 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.

  • 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

    Open the lab

Terraform · OphirCloud Academy · all lessons