DevOps and cloud / Intermediate / 5 min / Updated
Infrastructure as code: plan, apply and drift
Change Terraform-style code and read the plan. Console clicks cause drift, engine changes replace databases, and no state lock makes duplicates.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
What is infrastructure as code?
Infrastructure as code describes servers, networks and databases in versioned files; a tool plans the diff with reality and applies it.
Why does it matter?
Clicking in a console is not reviewable or repeatable. Code gives review, history and identical environments, and shows drift.
What is the trade-off?
Plans must be read: some changes replace resources and lose data. Shared state needs a lock, and console edits get reverted.
How do you explain it in an interview?
"Terraform in git, plan on every pull request, remote state with locking, apply only from CI, scheduled drift checks, prevent_destroy on databases."
Check yourself
Someone opens port 22 in the cloud console. What does the next plan show?
Answer: An update to close it again, because the code says closed (drift). Plan compares the real state with the code. Manual changes are drift and get reverted unless the code is changed too.
A plan says -/+ replace for your database. What does that mean?
Answer: Destroy the old one and create a new one, losing its data unless you migrate. Some attributes cannot change in place. Read every plan, and protect stateful resources with prevent_destroy and snapshots.
Why does Terraform lock its state during an apply?
Answer: So two applies cannot both act on the same plan and create duplicates or corrupt state. Remote state with locking lets only one apply run at a time.