← Back to Home
πŸ—οΈ

Introduction to Terraform

Describe your entire cloud infrastructure in code β€” and build it with one command.

⏱9 min readπŸ“šDevOps Fundamentals

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:


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:

πŸ’‘ 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:

text
You write:  "I want 3 servers and a load balancer"
Terraform:  compares desired vs actual β†’ makes the minimal changes

The 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:

hcl
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:

bash
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 down
bash β€” 80Γ—24
student@devops:~$terraform plan

plan shows you exactly what will happen before anything changes β€” no surprises.


πŸ§ͺ Hands-on Lab

πŸ“

Your First Terraform Config

  1. Write a config that uses the local provider to create a file resource
  2. Run terraform init, then plan
  3. Run apply and confirm the file was created

🧠 Knowledge Check

Knowledge Check

What does 'declarative' mean in Terraform?

Knowledge Check

Which command previews changes without making them?


πŸ’Ό Interview Preparation

Interview Q&A

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.

Up Next

Configuration & Variables

You've mastered this lesson. Continue your journey to becoming a DevOps Engineer.

Start Next Lesson→