Clicking in consoles doesn't scale, can't be reviewed and can't be reproduced; code can.
Infrastructure as code (IaC) means your servers, networks, DNS records and permissions are defined in files kept in git. Changes go through review, environments can be recreated, and the files document what exists.
Terraform is declarative: you describe the end state ("a bucket named logs with versioning on") and Terraform figures out the steps. Its core loop:
1. You write .tf files in HCL, HashiCorp's configuration language. 2. terraform plan compares your configuration with the state (Terraform's record of what it manages) and the real world, and shows what it would create, change or destroy. 3. terraform apply executes that plan through providers, plugins that talk to each API (AWS, Azure, Google Cloud, Kubernetes, GitHub, Cloudflare, Datadog...).
Compared with alternatives: CloudFormation and Bicep are tied to one cloud; Pulumi and CDKs use general-purpose languages; Ansible configures machines rather than provisioning cloud resources (the two are often combined).
OpenTofu is a community fork created after Terraform's licence moved to the BUSL in 2023; for everything in this course it behaves the same, with tofu in place of terraform.
The big rule: once Terraform manages something, change it through Terraform, not the console, or the next plan will try to undo your manual change.
Example
# main.tf: the whole idea in one resource
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 6.0" }
}
}
provider "aws" {
region = "eu-west-1"
}
resource "aws_s3_bucket" "logs" {
bucket = "acme-app-logs-prod"
}
# terraform init -> downloads the AWS provider
# terraform plan -> Plan: 1 to add, 0 to change, 0 to destroy.
# terraform apply -> aws_s3_bucket.logs: Creation completeRemember
- Declare the end state; Terraform computes and applies the diff
- plan shows changes before apply makes them
- Providers talk to the APIs; state records what Terraform manages
Watch out for
- Changing Terraform-managed resources in the console, then being surprised when apply reverts them.