Home / Terraform
Terraform
Infrastructure as code, from a first configuration to a three-tier app: HCL, core commands, variables, outputs, remote state, workspaces and modules — plus a VPC, an EC2 instance, IAM roles and a Lambda function. Every example run for real.
Terraform lets you describe infrastructure as code: servers, networks and databases written down in files, then created with one command. This course takes you from your first configuration to a three-tier app in the cloud, one short lesson at a time.
Course contents
Work top to bottom — the sidebar is the course. Topics later in the list assume the ones before them.
What Terraform Is
- What Is Terraform?
- What Is Infrastructure as Code?
- Terraform vs Ansible vs CloudFormation vs Pulumi
- Terraform, OpenTofu and the Licence Split
Install and First Project
- Install Terraform
- Your First Configuration
- The Terraform Workflow: Init, Plan, Apply
- Terraform Providers
- Your First Real Resource
Core Commands
- terraform init
- terraform plan
- terraform apply and terraform destroy
- terraform validate, fmt and graph
Writing Configuration
- HCL: Blocks, Arguments and Attributes
- Variables
- Variable Files and .tfvars
- Outputs
- Locals
- Environment Variables
State
- What Is Terraform State?
- Reading State
- State Is a Secret
- Remote State with an S3 Backend
- State Locking
- Drift: When Reality Changes
Environments
Start: Workspaces ❯Expressions and Logic
Start: Functions ❯Modules
- What Is a Module?
- Write Your First Module
- The Terraform Registry
- Module Inputs, Outputs and Versions
Real Infrastructure
- Networks: A VPC
- Compute: An EC2 Instance
- Identity: IAM Users and Roles
- Serverless: A Lambda Function
- A Second Cloud: Azure and GCP
Bringing Existing Infrastructure In
Start: Import Existing Resources ❯Testing, Security and Pipelines
Start: Test Your Configuration ❯Wrap-Up and Capstone
Start: Terraform Best Practices ❯What you will learn
You will write configurations in HCL, plan and apply changes, manage state and workspaces, and build real infrastructure: a VPC, an EC2 instance, IAM roles and a Lambda function.
You will also learn the habits that keep real Terraform projects safe: locking state, keeping secrets out of files, and importing what already exists instead of rebuilding it.
By the end of the course you will be able to:
- Write Terraform configurations in HCL
- Plan, apply and destroy infrastructure with the core commands
- Use variables, outputs, locals and functions
- Store state remotely and lock it against concurrent changes
- Split environments with workspaces
- Write reusable modules and use modules from the Registry
- Build a VPC, an EC2 instance, IAM roles and a Lambda function
- Import existing resources and run Terraform in CI/CD
How the course works
Every lesson is short, with a focused example first and one exercise at the end. Every closing example was run for real on Terraform 1.17.1, and its stated output is the real output.
The examples that touch AWS run against a local AWS emulator on your own machine, not a live account, so nothing here costs money or creates real cloud resources. The one lesson that looks at a second cloud says so plainly and is read-and-understand.
Frequently asked questions
Do I need an AWS account to follow this course?
No. The lessons that create AWS resources run against a local AWS emulator, so you can follow along with no account and no bill. The course tells you where to point Terraform at the emulator, and where the same configuration would point at real AWS.
Can Terraform run in the browser on this site?
No. Terraform needs its own binary and a local emulator, so the Try-it box shows the verified output from a real run instead of running the commands here.
What version of Terraform do the examples use?
Terraform 1.17.1, with the AWS provider 6.72.0. The commands work on any recent Terraform 1.x version.
Is Terraform free?
Yes, Terraform is free to download and use. The course also covers the licence split that led to OpenTofu, so you know where the two projects stand.
Next steps
- What Is Terraform? ❯ — Start the course: the problem Terraform solves.
- Your First Real Resource ❯ — Create a real resource and see it in state.
- Capstone: A Three-Tier App ❯ — The capstone: network, compute and data, wired together.