design·lab

DevOps & platform

Infrastructure as Code

Declare the servers you want in a file, and let a tool reconcile the real cloud to match it — instead of clicking buttons in a console and hoping someone remembers what was clicked.

✗ The problem

Click-ops: infra nobody can reproduce

Every server is provisioned by hand in a web console. There's no record of what was clicked, no review before a change ships, and no way to tell what silently drifted.

// nobody wrote this down:
1. Console → EC2 → Launch Instance
2. Pick AMI, size, VPC… by hand
3. Repeat for server #2, #3…
4. Someone "just tweaks one setting"
web-1
t3.micro
web-2
t3.large??
web-3
???
Snowflake servers, silent drift, no code review, no history of what changed — and no one can rebuild it from scratch.
✓ How it works

Declare desired state as code

Terraform reads the code, plan diffs it against the real world, and apply reconciles the cloud to match. A state file tracks what's real; modules make it reusable.

resource "aws_instance" "web" {
  ami           = "ami-0abc"
  instance_type = "t3.micro"
  count         = 2
}
HCL code
desired state
↓ plan (diff)
terraform plan
+2 to add
↓ apply (reconcile)
Cloud
state file tracks it
$ terraform plan
  + aws_instance.web[0]  will be created
  + aws_instance.web[1]  will be created
Plan: 2 to add, 0 to change, 0 to destroy.
✓ See it live

Scale up, apply, then watch drift get caught

Edit the code from 2 → 3 servers, plan the diff, apply it — then simulate someone deleting a server by hand and plan again.

Desired (code)

Actual (cloud)

✓ Takeaway

Code is the source of truth

  • Reproducible + reviewable + versioned: infra changes go through the same PR review as app code.
  • Plan before apply: always see the exact diff before anything touches the real world.
  • Idempotent convergence: running apply twice with no code change does nothing the second time.
  • Detect & correct drift: manual changes outside Terraform get flagged on the next plan.
  • Modules for reuse: package a reviewed pattern once, reuse it across teams and environments.
🎯 Same declarative/reconcile idea as Kubernetes and GitOps — describe the desired state, let a controller converge reality to it.