Free tutorial · 25 lessons

Terraform Tutorial

Learn Terraform and infrastructure as code from scratch: providers, resources, variables, expressions, loops, state, remote backends, modules, testing and CI/CD, with real configurations and the output Terraform prints.

Start learning →

Terraform Basics

  1. Terraform Introduction — What Terraform is, what infrastructure as code means, and why teams use it to create and change cloud infrastructure safely.
  2. Terraform Get Started — Install Terraform, learn the init → plan → apply → destroy workflow, and understand the files Terraform creates.
  3. Terraform Syntax (HCL) — Blocks, arguments, labels, comments and expressions: how Terraform configuration files are written.
  4. Terraform Providers — Providers are plugins that let Terraform manage a platform such as AWS, Azure, Google Cloud or Kubernetes. Learn how to declare, configure and pin them.
  5. Terraform Resources — Resources are the infrastructure objects Terraform creates and manages. Learn the resource syntax, references between resources, dependencies and lifecycle rules.
  6. Terraform Variables — Input variables make configurations reusable. Learn to declare variables with types, defaults, descriptions, validation and sensitive values, and how to set them.
  7. Terraform Outputs — Outputs expose values from a configuration: to the command line, to scripts, and to other configurations and modules.
  8. Terraform Locals — Local values give a name to an expression so you can reuse it. Use them to avoid repetition and keep configurations readable.
  9. Terraform History & Versions — How HashiCorp created Terraform, the jump to HCL2 and 1.0, the 2023 licence change and the OpenTofu fork, every important release on one timeline, and how Terraform compares with other infrastructure-as-code tools.

Terraform Language

  1. Terraform Types — Terraform's type system: strings, numbers, booleans, lists, sets, maps, objects and tuples, and how to declare them for variables.
  2. Terraform Expressions — Operators, conditional expressions, string templates and splat expressions: how to compute values in Terraform.
  3. Terraform Functions — Terraform's built-in functions for strings, numbers, collections, encoding, files, dates and IP networks, with examples you can try in terraform console.
  4. Terraform count and for_each — Create several copies of a resource with count or for_each, and learn why for_each is usually the safer choice.
  5. Terraform for Expressions — Transform lists and maps with for expressions: filter, reshape and build new collections.
  6. Terraform Dynamic Blocks — Generate repeated nested blocks, such as security group rules, from a list or map with dynamic blocks.

State and Workflow

  1. Terraform State — The state file is how Terraform remembers what it manages. Learn what's in it, why it matters, and the commands to inspect it safely.
  2. Terraform Remote State and Backends — Store state remotely with locking so teams and CI pipelines can share it safely: S3, Azure Storage, Google Cloud Storage and HCP Terraform.
  3. Terraform Data Sources — Data sources read information that exists outside your configuration, such as the latest AMI, the current account or an existing VPC, without managing it.
  4. Terraform import, moved and removed — Bring existing infrastructure under Terraform with import blocks, and rename or stop managing resources safely with moved and removed blocks.
  5. Terraform Environments and Workspaces — Run the same configuration for dev, staging and production: separate directories, tfvars files, and when (not) to use workspaces.

Modules and Quality

  1. Terraform Modules — Modules package configuration for reuse. Learn to write a module with inputs and outputs, call it, version it, and use modules from the Terraform Registry.
  2. Terraform Validation and Checks — Catch mistakes early with variable validation, preconditions and postconditions on resources, and check blocks that continuously verify your infrastructure.
  3. Terraform Testing — Test modules with terraform test: write .tftest.hcl files with run blocks and assertions, plan-only tests and mocked providers.
  4. Terraform CI/CD and Best Practices — Run Terraform safely in a team: plans on pull requests, applies from CI, formatting and security checks, and the habits that keep infrastructure code healthy.
  5. Terraform Next Steps — Where to go after the Terraform tutorial: the deep course, interview questions, a quiz, and official resources.