DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

Tutorial

Terraform Tutorial

Learn Terraform from scratch: Infrastructure as Code fundamentals, the core workflow, variables, state management and reusable modules with hands-on examples.

Start Learning

34 lessons in this tutorial

1

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.

2

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.

3

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.

4

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.

5

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.

6

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.

7

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.

8

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.

9

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.

10

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.

11

Terraform Output Values

Learn Terraform output values in depth, including output blocks, sensitive outputs, terraform output commands, module outputs, and CI/CD automation patterns.

12

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.

13

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.

14

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.

15

Terraform State Commands

Learn the most important Terraform state and import commands, including terraform state list, show, mv, rm, import, and refresh-related workflows.

16

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.

17

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.

18

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.

19

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.

20

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.

21

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.

22

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.

23

Terraform Expressions and Functions

Get a quick overview of Terraform expressions and built-in functions before diving into string operations and collection transformations.

24

Terraform String Functions

Learn Terraform string interpolation, formatting, replacements, regex helpers, templatefile, conditionals, and other string-oriented expressions used in real infrastructure code.

25

Terraform Collection Functions

Learn Terraform list, map, set, and type-conversion functions, plus for expressions and transformation patterns for dynamic infrastructure code.

26

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.

27

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.

28

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.

29

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.

30

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.

31

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.

32

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.

33

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.

34

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.