What Terraform Is & Why It Exists

Terraform / Infrastructure as Code

Chapter 1 · What Terraform Is & Why It Exists

cloud1-11 gave Infrastructure as Code a first look — declarative vs. imperative, Terraform named as the cross-provider option, plan/apply and configuration drift introduced at a conceptual level. This course goes deep specifically on Terraform itself: not IaC in general, but this one tool, in real depth.

The Configuration Drift Problem

A server gets provisioned by hand through a cloud console. Six months later, nobody fully remembers which settings were changed, when, or why — a firewall rule added during an incident, a instance size bumped up "temporarily" during a traffic spike and never reverted. Staging quietly stops matching production. This is configuration drift, and it's the exact problem cloud1-11 named but didn't solve: infrastructure that exists only in a console, with no record of its own history, and no reliable way to reproduce it.

Declarative vs. Imperative Infrastructure

An imperative script says exactly what steps to run, in order: "create a VM, then attach a disk, then open port 443." Run it twice and it may fail the second time (the VM already exists) or duplicate resources. A declarative tool like Terraform instead says what the end state should look like — "there should be one VM, with this disk, with this port open" — and lets Terraform figure out what actions are needed to get there, including doing nothing if reality already matches.

# A conceptual preview — real syntax and installation come in Chapter 2 resource "aws_instance" "web" { ami = "ami-0abcdef1234567890" instance_type = "t3.micro" }

That block doesn't say "run these commands" — it says "this instance should exist, with these properties." Terraform compares that declared intent against what's actually running and works out the difference itself.

Terraform vs. the Cloud-Native Alternatives

ToolProvider ScopeLanguage
TerraformCross-provider — AWS, Azure, GCP, and hundreds of others via a shared provider modelHCL (HashiCorp Configuration Language)
CloudFormationAWS onlyJSON/YAML
ARM / BicepAzure onlyJSON / Bicep DSL
Deployment ManagerGCP onlyYAML/Jinja2/Python

Each cloud-native tool is genuinely well-integrated with its own provider — but locked to it. Terraform's core value, especially relevant given cloud1-2's own cross-provider terminology map, is expressing infrastructure across providers (or a multi-cloud environment) using one consistent language and workflow.

Terraform vs. Ansible — Two Different Jobs

Terraform provisions infrastructure — it creates the VM, the network, the database instance. It has no concept of "log in and install a package." Ansible configures infrastructure that already exists — installing software, editing config files, restarting services, on machines Terraform (or something else) has already brought into being. They're complementary, not competing: a real pipeline commonly runs Terraform first to create the servers, then Ansible to configure them.

The Terraform Workflow: Write → Plan → Apply → Destroy

  • Write — describe desired infrastructure in .tf configuration files
  • Plan — Terraform compares desired state against actual state and shows exactly what it intends to change, before touching anything
  • Apply — Terraform executes that plan, creating/updating/deleting only what's needed
  • Destroy — Terraform tears down everything it manages, cleanly, in dependency order

The plan step is the single biggest practical difference from clicking through a console: you see the change before it happens, every time.

When Terraform Fits — and When It Doesn't

A one-off resource for quick local testing, or a genuinely single, tiny, rarely-touched environment, often isn't worth the ceremony. Terraform earns its keep once infrastructure needs to be reproducible, reviewed by a team, or exist in more than one environment (dev/staging/prod) — exactly the scenarios where console-driven drift becomes a real, recurring problem.

The plan step is the point
Most of Terraform's real-world value comes from one habit: never apply a change you haven't first reviewed via plan. It's the single practice most responsible for catching unintended changes before they happen.
Provisioning ≠ configuring
Don't reach for Terraform to install software or edit files on a running server — that's Ansible's job (still on this site's own bucket list). Mixing the two responsibilities into one tool is a common early mistake.

Hands-On Exercises

Exercise 1

Explain, in your own words, why a declarative tool comparing desired state against actual state avoids the "run it twice and it breaks" problem that an imperative script has.

📄 View solution
Exercise 2

A team wants to manage infrastructure spread across AWS and Azure with one consistent workflow. Explain why CloudFormation is a poor fit here, and why Terraform is.

📄 View solution
Exercise 3

A colleague suggests using Terraform to install and configure nginx on an existing server. Explain why this is the wrong tool for that specific job, and name the right one.

📄 View solution

Chapter 1 Quick Reference

  • Configuration drift — infrastructure changed by hand, with no record, that quietly diverges from what's expected
  • Declarative — describe the desired end state; the tool figures out the steps
  • Terraform vs. CloudFormation/ARM/Deployment Manager — cross-provider vs. single-cloud-native
  • Terraform vs. Ansible — provisions infrastructure vs. configures infrastructure that already exists
  • Workflow — write → plan → apply → destroy, with plan as the review step before anything changes