DEPLOYEDAI-era interview training
RankBootstrapping
XP 0 / 250
0
0%
Ready
DevOps, SRE & Cloud Interview · Infrastructure as Code & Config · Lesson 1 of 2

IaC & Terraform: declarative & idempotent

7 min

Infrastructure as Code (IaC) means provisioning infrastructure from version-controlled, reviewable definitions instead of clicking in a console. Terraform (or its open-source fork OpenTofu) is the dominant tool: you declare the desired state, and it computes and applies the diff to reach it.

  • Declarative: you describe what you want (an S3 bucket, a VPC), not the API calls to create it. Terraform builds a dependency graph and figures out the ordering.
  • Idempotent: applying the same config repeatedly converges to the same state. If reality already matches, terraform apply does nothing — running it twice is safe.
  • Plan then apply: terraform plan shows exactly what will change before you commit; review it like code.
  • Providers translate config into cloud API calls (AWS, GCP, Azure, Kubernetes, and more) behind one workflow.
Declarative vs imperativeAn imperative script says 'create a server, then a disk, then attach it' — and breaks if run twice. A declarative config says 'a server with this disk exists'; the tool reconciles reality to that, whether starting from nothing or a partial state. That is why IaC is idempotent.
Do not change infra by handEditing resources in the console behind Terraform's back creates drift — the real state no longer matches the code. The next apply may revert or conflict. Change infra only through the code; use terraform plan to detect drift.

◆ Lock it in

  • IaC = version-controlled, reviewable infra; Terraform applies a diff toward declared desired state.
  • Declarative + idempotent: re-applying the same config is safe and converges to the same result.
  • Always plan before apply; never change managed infra by hand (drift).
Feynman drill — say it out loudExplain what 'idempotent' means for Terraform and why declarative infra avoids the pitfalls of a shell script.
Step 1 rate your confidence · Step 2 pick your answer
What does it mean that Terraform is idempotent?
Step 1 — how sure are you?