Terraform Tutorial
Learn Terraform from scratch: Infrastructure as Code fundamentals, the core workflow, variables, state management and reusable modules with hands-on examples.
34 lessons in this tutorial
Introduction to Terraform
Learn what Terraform is, how Infrastructure as Code works, why it beats clicking through cloud consoles, and how Terraform compares to Ansible, CloudFormation and Pulumi.
Installing Terraform
Step-by-step guide to installing Terraform on macOS, Linux and Windows using the official HashiCorp package managers. Verify the install and run your first real Terraform configuration.
The Terraform Core Workflow
The four commands that power every Terraform project, init, plan, apply, and destroy. Learn the complete workflow loop used by every DevOps engineer managing infrastructure as code.
terraform init
Learn exactly what terraform init does, downloading providers, setting up backends, creating the lock file, and how to use init flags like -upgrade and -reconfigure.
terraform plan
Master terraform plan, understand execution plan output symbols (+/-/~/+/-), save plan files, target specific resources, detect configuration drift, and use plan in CI/CD pipelines.
terraform apply
Learn terraform apply in depth, reviewing and confirming the plan, auto-approve for CI/CD, applying saved plan files, parallel execution, watching real-time output, and handling apply errors safely.
terraform destroy
Learn terraform destroy, safely tearing down infrastructure, using -target for partial destroys, understanding the destroy plan, and when to use destroy vs decommission. Includes terraform fmt and validate.
Terraform Variables and Outputs
Learn how Terraform input variables, local values, and output values work together to make infrastructure code reusable, readable, and easier to share across environments.
Terraform Input Variables
Learn Terraform input variables in depth, including variable blocks, types, defaults, validation rules, tfvars files, CLI flags, environment variables, and sensitive values.
Terraform Local Values
Learn how Terraform local values work, when to use locals instead of variables or data sources, and how to simplify repetitive expressions in your infrastructure code.
Terraform Output Values
Learn Terraform output values in depth, including output blocks, sensitive outputs, terraform output commands, module outputs, and CI/CD automation patterns.
Terraform State and Backends
Learn the big picture of Terraform state, remote backends, and state management commands so you can work safely with real infrastructure and collaborate with confidence.
Terraform State Overview
Learn what Terraform state is, why the terraform.tfstate file exists, how it maps to real infrastructure, and why state security and locking matter in production.
Terraform Remote Backends
Learn why Terraform remote backends matter, how to configure S3 with DynamoDB locking, when to use Terraform Cloud or GCS, and how to migrate state safely.
Terraform State Commands
Learn the most important Terraform state and import commands, including terraform state list, show, mv, rm, import, and refresh-related workflows.
Terraform Modules
Learn the big picture of Terraform modules, how to use existing modules safely, and how to write your own reusable modules for cleaner infrastructure code.
Using Terraform Modules
Learn how to use Terraform modules from local paths and the Terraform Registry, pass inputs, pin versions, run terraform init, and consume module outputs.
Writing Terraform Modules
Learn how to write reusable Terraform modules, structure them with main.tf, variables.tf, and outputs.tf, and publish or share modules across projects.
Terraform Data Sources
Learn how Terraform data sources read existing infrastructure, how data blocks work, how outputs are referenced, and when to use data sources instead of resources.
Terraform Count and for_each
Get a quick overview of Terraform count and for_each so you can choose the right repetition pattern before learning each meta-argument in detail.
Terraform Count
Learn how Terraform count works, how count.index is used, how to create conditional resources, how to reference counted resources, and when count is a good fit.
Terraform for_each
Learn how Terraform for_each works with maps, sets, and transformed collections, how to reference named instances, and when for_each is better than count.
Terraform Expressions and Functions
Get a quick overview of Terraform expressions and built-in functions before diving into string operations and collection transformations.
Terraform String Functions
Learn Terraform string interpolation, formatting, replacements, regex helpers, templatefile, conditionals, and other string-oriented expressions used in real infrastructure code.
Terraform Collection Functions
Learn Terraform list, map, set, and type-conversion functions, plus for expressions and transformation patterns for dynamic infrastructure code.
Terraform Dynamic Blocks
Learn how Terraform dynamic blocks generate nested configuration, where they fit well, how to use them safely, and when they make code too complex.
Terraform Workspaces
Learn what Terraform workspaces are, how workspace commands work, how state is separated, and when workspaces are helpful or the wrong environment strategy.
Terraform with AWS
Build a complete AWS project with Terraform by combining a custom VPC, a public EC2 web server, and an S3 bucket for static assets.
Terraform AWS VPC Setup
Build a custom AWS VPC with Terraform, including public and private subnets, an internet gateway, route tables, and a NAT gateway.
Terraform AWS EC2 Web Server
Continue the AWS Terraform project by launching an EC2 web server with a security group, key pair, user data, and Elastic IP.
Terraform AWS S3 Static Assets
Continue the AWS Terraform project by creating an S3 bucket for static assets with versioning, lifecycle rules, public-read policy, and object uploads.
Terraform Provisioners
Learn what Terraform provisioners are, how local-exec, remote-exec, file, connection blocks, and null_resource work, and why provisioners should be a last resort.
Terraform CI/CD Pipeline
Build a GitLab CI/CD pipeline for Terraform with validate, plan, apply, and destroy stages, environment controls, remote state, and secure credentials handling.
Terraform Security
Learn how to scan Terraform code with tfsec and Checkov, protect secrets in state, secure backends, and integrate IaC security checks into CI/CD.