CD3: Terraform foundations

Lesson 1 of 5 · reading 15–25 minutes; practice and project time is on the module page

Why infrastructure as code, and how Terraform works

🎯You'll be able to

Explain what infrastructure as code solves, and run Terraform's basic cycle: init, plan, apply and destroy.

🏠The everyday picture

An architect's drawing describes the finished building. Builders compare the drawing with the site and do whatever is missing. If a wall is built wrongly, they check against the drawing, not against someone's memory. And the same drawing can build an identical second house.

📘What it really is

📝A worked example

Input: in the starter kit, cd infra, terraform init, then terraform plan.

Expected output: init downloads the Docker provider; plan lists 7 resources to create (the network, three images, the database, the API and the load balancer) and ends with Plan: 7 to add, 0 to change, 0 to destroy. After Project 1 the plan has 11 (adding a volume, a generated password, a random suffix and a second API copy), and 15 with -var monitoring=true. Counted on 1 November 2026 with Terraform 1.17.1.

🌍Where it's used

📝Case scenario

A hospital chain had three "identical" environments built by hand over two years. A booking bug appeared only in production; after a week of searching, they found a database setting someone had changed in production during an incident and never copied elsewhere. After moving to Terraform, the three environments came from the same files with different sizes, and a difference like that showed up in a plan.

🖱️Try it

Run terraform plan in the starter's infra/ folder, then terraform apply, then terraform plan again. Success: the first plan shows 7 to add, the apply creates them, and the last plan says No changes. Your infrastructure matches the configuration.

⚠️Common mistakes

🛠️For your project

Project 1 is an environment built entirely from the files in infra/; tests 7, 8 and 10 check that plan, drift repair and rebuild work.

✅Quick check

What does "declarative" mean for Terraform?

Show the answer

You describe what should exist, and Terraform works out what to create, change or delete.

What does terraform plan do?

Show the answer

Compares the files with what exists and shows the changes it would make, without making them.

← BackCD3
ProLearners Assist