Terraform Tutorial

Learn Terraform infrastructure as code: the plan/apply workflow, variables, providers, count and for_each, state, modules, environments, testing, and a real AWS project.

Terraform lets you describe infrastructure — servers, networks, DNS records, buckets, even GitHub repositories — in configuration files, review the exact changes as a plan, and apply them repeatably. It is the most widely used infrastructure-as-code tool, and the same workflow works across AWS, Azure, Google Cloud and hundreds of other providers.

This path starts with the init/plan/apply loop on your own machine with no cloud account needed, then covers variables and expressions, providers and resources, count, for_each and dynamic blocks, data sources and lifecycle rules. The second half covers what teams need in production: remote state and locking, refactoring with moved blocks, reusable modules, multiple environments, automated tests and CI, and a complete static-website project on AWS. Each article states exactly which examples were applied and which were validated against mocked providers.

What You'll Learn

  • Getting Started
  • Core Concepts
  • State and Modules
  • Production Workflows

10 tutorials · Beginner to advanced · Exercises with solutions in every article · Free, no sign-up

Start here

Terraform Introduction

What Terraform is, how the write-plan-apply workflow works, and your first real configuration, tested end to end on Terraform 1.17 with no cloud account.

Section 1. Getting Started

Start here to learn the Terraform basics.

  • —Terraform Introduction – What Terraform is, how the write-plan-apply workflow works, and your first real configuration, tested end to end on Terraform 1.17 with no cloud account.
  • —Variables, Locals, Outputs, and Expressions – Make one Terraform configuration serve dev, staging and prod with typed input variables, validation, locals, outputs, for expressions and built-in functions.

Section 2. Core Concepts

  • —Providers and Resources – How Terraform providers are declared, pinned and configured, how resource blocks become real objects, and how to read create, update-in-place and replace plans.
  • —count, for_each, and Dynamic Blocks – Create many resources from one block with count and for_each, avoid the index-shift trap, make resources conditional, and generate nested blocks with dynamic.
  • —Data Sources, Dependencies, and Lifecycle Rules – Read existing infrastructure with data sources, control ordering with references and depends_on, and guard risky changes with lifecycle rules, conditions and -replace.

Section 3. State and Modules

  • —Terraform State: Backends, Locking, and Refactoring – What Terraform state holds, where to store it, how locking protects it, and how to rename, import, hand over and drift-check resources without destroying anything.
  • —Writing and Using Modules – Turn copy-pasted Terraform into reusable modules: inputs, outputs and versions.tf, for_each over modules, composition, registry and git sources, and moved blocks.

Section 4. Production Workflows

  • —Managing Multiple Environments – Run dev, staging and prod from one Terraform codebase: workspaces and their limits, directory-per-environment layouts, per-environment backends and tfvars, and versioned promotion.
  • —Testing and CI for Terraform – Catch Terraform mistakes before they reach production: fmt and validate, the native test framework with mocks, saved plans, policy checks on plan JSON, and a GitHub Actions pipeline.
  • —Capstone: A Static Website on AWS – Build a production-ready static site on AWS with Terraform: a private S3 bucket behind CloudFront with Origin Access Control, optional custom domain, tests, and two environments.