Stop 09 · Infrastructure as CodeTopics · 2/9

Terraform Fundamentals

Part of the DevOps Roadmap

In short

Terraform is the most common way teams write infrastructure as code across clouds. Learn its four-word loop (write, init, plan, apply) and you can read most real-world setups.

The most widely used cloud-agnostic IaC tool — describing infrastructure in HCL (HashiCorp Configuration Language) and letting Terraform plan and apply the changes needed to reach that state.

The mascot compares a half-empty kitchen shelf with a picture list, holding a basket of missing jars.

Think of it like this

The kitchen shopping list

Before going to the kirana store, you check the shelves against the list: atta there, sugar missing, oil low. You only buy what's missing. Terraform does the same. Your code is the list, the cloud is the shelf, and plan tells you exactly what it will add, change or remove.

Watch it happen

The Terraform loop

Write .tf
init
plan
apply
state

1/5You describe resources in .tf files using HCL: an instance, its size, its tags.

The big ideas

What you need to know

Providers talk to APIs

AWS, Azure, GCP, Cloudflare, GitHub: each provider turns HCL resources into that service's API calls.

Resources and data

A resource block creates something. A data block only reads something that already exists.

Variables and outputs

Variables make code reusable. Outputs expose values like an IP address after apply.

Dependency graph

Terraform works out the order from references. A subnet that uses a VPC's ID is created after that VPC.

See it in code

Walk through the code

hcl
1variable "env" { default = "dev" }2 3resource "aws_instance" "web" {4  ami           = "ami-0abcdef1234567890" # pick a real AMI for your region5  instance_type = "t3.micro"6  tags          = { Name = "web-${var.env}" }7}8 9output "public_ip" {10  value = aws_instance.web.public_ip11}

1/3A variable with a default. Override it with -var env=prod or a .tfvars file.

Run terraform init, plan, apply, and terraform destroy when you're done. A running instance costs money, so check current free tier terms before you start.

Save yourself the pain

Common mistakes

Oops

Running terraform apply without reading the plan.

Do this instead

Read every line, especially anything marked 'must be replaced' or 'destroy'. Some changes recreate a resource and lose its data.

Oops

Leaving practice resources running after a tutorial.

Do this instead

Run terraform destroy at the end of each session and set a billing alert on your cloud account.

Your mission

Terraform without a cloud bill

~25 min

Quick check

What does terraform plan do?

Go deeper

  1. 1Write a simple Terraform configuration provisioning a basic cloud resource (e.g. an S3 bucket).
  2. 2Practice the core workflow: terraform init, plan, apply.
  3. 3Learn to always review a terraform plan output before applying, especially on real infrastructure.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge