Lesson 1 / 25

Why Infrastructure as Code

Reviewable, repeatable infrastructure.

Code instead of console clicks

Infrastructure as code (IaC) describes servers, networks, databases, DNS records and permissions in text files kept in version control. Changes are reviewed like code, environments can be recreated consistently, and the history shows who changed what. Terraform (by HashiCorp, with the open-source fork OpenTofu largely compatible) is a declarative IaC tool: you describe the desired end state in HCL (HashiCorp Configuration Language) and Terraform works out the API calls needed to reach it, across hundreds of providers (AWS, Azure, Google Cloud, Kubernetes, GitHub, Cloudflare and more).

Describe infrastructure, let Terraform build it

Terraform turns declarative configuration into API calls, using a plan you can review first.

Three ideas: infrastructure as code, the workflow, providers.
Figure 1.1 — IaC, workflow and providers.

Architect's drawings

Builders follow drawings that can be reviewed, copied and amended; nobody improvises a building from memory. IaC is the drawing set for infrastructure.

Stop changing things by hand

Manual console changes create drift that Terraform will try to undo; make every change through code.

Quick check: What does "declarative" mean for Terraform?

  • Changes are made only by clicking
  • You write each API call in order
  • You describe the desired end state and Terraform works out the steps
  • It only reads infrastructure
Answer

You describe the desired end state and Terraform works out the steps — Desired state in, plan out.