Terraform & IaC
State, modules, plan/apply discipline, drift detection, workspaces. "How do you review infra changes?" is a favorite probe.
The mental model
Terraform is a reconciliation loop you run by hand. You write down the world you want (HCL files), Terraform reads the world that exists (state + provider APIs), computes the difference, and shows you the exact surgery it will perform before touching anything.
The analogy that sticks: Terraform is an architect's blueprint plus a building inspector. The blueprint (.tf files) says "3-story building, 2 elevators." The inspector's report (terraform plan) says "currently 2 stories, 1 elevator — I will add 1 story and 1 elevator, and demolish nothing." Only when you sign off (terraform apply) does construction start. The inspector's notebook — the record of what was actually built and its serial numbers — is the state file. Lose the notebook and the inspector no longer knows which buildings are yours; Terraform will either try to rebuild everything or fight with what already exists.
Three ideas carry the whole tool:
- Declarative, not imperative: you never write "create a VM," you write "a VM exists." Order is derived from the dependency graph, not from your file order.
- State is the source of truth about ownership, not about reality. Reality can drift; state records what Terraform believes it manages and the IDs it needs to manage it.
- Plan is a contract: what apply does is what plan showed — as long as nothing changed in between (this is why state locking exists).
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision