Introduction to Terraform
Describe your entire cloud infrastructure in code β and build it with one command.
Clicking through a cloud console to create servers works once β but itβs slow, error-prone, and impossible to reproduce. Terraform lets you describe your infrastructure in code, so you can create, change, and destroy it reliably and repeatably. This is Infrastructure as Code (IaC).
π― Learning Objectives
By the end of this lesson you will:
- Understand what Infrastructure as Code means
- Know what Terraform is and how it works
- Understand providers, resources, and the core workflow
- Recognise why declarative infrastructure matters
What is Infrastructure as Code?
Instead of manually provisioning servers, networks, and databases through a web console, you write code that describes what you want. That code is:
- Version-controlled β every change is tracked in Git.
- Reviewable β infrastructure changes go through pull requests.
- Repeatable β spin up an identical environment any time.
- Documented β the code is the documentation.
π‘ Click-ops vs code
Manually clicking in a console is βclick-opsβ: fast to start, impossible to reproduce. IaC trades a little upfront effort for infrastructure you can rebuild identically, forever.
What Makes Terraform Special
Terraform is cloud-agnostic and declarative:
- Cloud-agnostic β the same tool manages AWS, Azure, GCP, Kubernetes, and hundreds of other platforms through providers.
- Declarative β you describe the desired end state, and Terraform figures out the steps to get there (create, update, or delete resources as needed).
You write: "I want 3 servers and a load balancer"
Terraform: compares desired vs actual β makes the minimal changesThe Building Blocks
| Concept | What it is |
|---|---|
| Provider | A plugin for a platform (aws, azurerm, google, kubernetes) |
| Resource | A single piece of infrastructure (a server, a bucket, a DNS record) |
| State | Terraformβs record of what it has created |
| Plan | A preview of the changes Terraform will make |
A tiny example that creates an AWS S3 bucket:
terraform {
required_providers {
aws = { source = "hashicorp/aws" }
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "data" {
bucket = "my-devops-course-bucket"
}The language is HCL (HashiCorp Configuration Language) β readable and purpose-built for infrastructure.
The Core Workflow
Three commands do almost everything:
terraform init # download providers, set up the working dir
terraform plan # preview what will change
terraform apply # make it real
terraform destroy # tear it all downplan shows you exactly what will happen before anything changes β no surprises.
π§ͺ Hands-on Lab
Your First Terraform Config
- Write a config that uses the
localprovider to create a file resource - Run
terraform init, thenplan - Run
applyand confirm the file was created
π§ Knowledge Check
What does 'declarative' mean in Terraform?
Which command previews changes without making them?
πΌ Interview Preparation
Why is Infrastructure as Code important, and why Terraform specifically?
Summary
You now understand Infrastructure as Code, what Terraform is, its building blocks (providers, resources, state, plan), and the init β plan β apply workflow. Next, youβll write real configuration with variables and outputs.