Infrastructure as Code — Cloud in Text Files
What you'll learn
- Why clicking in the cloud console doesn't scale
- Infrastructure as Code (IaC) — defining servers in text
- Terraform and the declarative idea
- You'll parse a mini infrastructure config
Blueprints, not handcrafting 📐
Imagine building 50 identical servers by clicking through a web console for each one. Slow, error-prone, and impossible to reproduce exactly. Now imagine a colleague asks "how is production set up?" — nobody truly knows, because it was all click-click-click over two years.
Infrastructure as Code (IaC) fixes this: you describe your entire cloud setup — servers, databases, networks, permissions — in text files, and a tool builds it for you. The infrastructure becomes a blueprint you can version in Git, review, and reproduce perfectly.
The most popular tool is Terraform. You write what you want (declarative), not how to build it:
resource "aws_instance" "web" {
ami = "ami-12345"
instance_type = "t2.micro"
tags = {
Name = "web-server"
}
}
Run terraform apply and it creates exactly that server. Change t2.micro to t2.large and apply again — it resizes. Delete the block and apply — it removes the server. Your infrastructure now matches your code, always.
Why this is transformative:
- Reproducible — spin up an identical staging copy of production in minutes.
- Version-controlled — every infrastructure change is a Git commit you can review and roll back (remember Git from the frontend track?).
- Documented — the code is the documentation; there's no "mystery setup."
- Fast & safe — no manual clicking means no forgotten steps or human slips.
Declarative vs imperative: IaC is declarative — you state the desired end result ("I want one t2.micro server") and the tool figures out the steps. That's different from imperative code where you list every action. Declarative is why IaC is so reliable: you describe the destination, not the route.
This is a core skill for cloud engineers and DevOps — companies run entire global infrastructures from a folder of text files.
State files and drift: keeping the blueprint honest 📋
Terraform's declarative model has a subtle requirement: to know what to change, it needs to know what it already built. That record is the state file — Terraform's memory of every resource it created, matched to the config that describes it.
Every time you run terraform apply, Terraform does three things: reads your config (desired state), reads the state file (what it believes exists), and compares them to compute the minimal set of changes needed. This is why deleting a block and applying removes exactly that resource — Terraform diffs desired vs. remembered state, not desired vs. "everything in the cloud."
This creates a real risk called drift: when someone manually changes a resource outside of Terraform — clicking in the AWS console to resize a server "just this once" — the actual cloud no longer matches the state file. Terraform doesn't know about the change until you run it again, at which point it may try to "fix" your manual tweak back to what the code says, silently undoing work, or the reverse: you assume the code describes reality when it no longer does.
The discipline that avoids drift is simple but strict: all changes go through code, always — no manual console clicks on Terraform-managed resources, ever. Teams also run scheduled terraform plan checks specifically to catch drift early, before it causes an incident. This is the same discipline as "the code is the documentation" from earlier in this lesson — the moment reality diverges from the code, that promise is broken.
IaC tools read config and report what they'll build. Write summarize(resources) where resources is an array of { type, name } objects. Return a string like "2 resources: web (aws_instance), db (aws_db)" — the count, then each name with its type in parentheses, comma-separated.
Build a drift detector. Write findDrift(stateValues, actualValues) — both are objects mapping resource name to a value (e.g. instance type). Return an array of resource names where actualValues[name] does not equal stateValues[name] — these are the resources that drifted from what Terraform's state file expects. Return names in the order they appear in stateValues.
Real-world case study: HashiCorp and the rise of IaC 🔍
Terraform was first released in 2014 by HashiCorp, at a time when most companies still configured cloud servers by hand or with ad-hoc scripts. Its core bet — that infrastructure should be described declaratively in a cloud-agnostic language and version-controlled like application code — was unproven at the scale it eventually reached.
A decade later, Terraform had become the de facto standard for IaC across the industry, used by a large share of companies running production workloads on AWS, Azure, and Google Cloud, specifically because it solved the "nobody knows how production is configured" problem described at the start of this lesson at massive scale. Large enterprises with thousands of cloud resources now manage them from version-controlled repositories of Terraform files, with changes reviewed like any other code change before they touch production.
The broader lesson mirrors this lesson's theme directly: the industry converged on Terraform not because clicking in a console was impossible, but because at any real scale, undocumented manual infrastructure becomes unmanageable risk — while code that describes infrastructure is reviewable, testable, and recoverable. IaC went from a nice-to-have to the baseline expectation for any serious cloud operation.
Question 1 of 5
What is Infrastructure as Code?
Question 2 of 5
IaC is 'declarative'. That means…
Question 3 of 5
A key benefit of IaC is…
Question 4 of 5
What is a Terraform 'state file' for?
Question 5 of 5
What is 'drift' in Infrastructure as Code?
Summary
- IaC defines infrastructure in text files instead of manual clicking
- Terraform is the popular declarative tool: describe what you want, it builds it
- Benefits: reproducible, version-controlled, documented, safe
- The state file tracks what's built, and drift happens when manual changes desync it from reality
- You parsed a mini resource config and wrote a drift detector
- Terraform's rise shows how IaC became the baseline expectation for serious cloud operations
Next: Cloud Security — protecting all this infrastructure (IAM, encryption, the shared responsibility model).
Practice
Reading is not learning until you run something. Pick one.