Tutorial

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

1

Introduction to Terraform

What Terraform is and how Infrastructure as Code works. Why it beats clicking through consoles, and how it compares to Ansible and CloudFormation.

2

Installing Terraform

Install Terraform on macOS, Linux and Windows using the official HashiCorp package managers, verify it, and run your first real configuration.

3

The Terraform Core Workflow

The init, plan, apply, destroy loop. What each command does, how to read a plan, and the mistakes that cause outages.

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. Reading the output symbols, saving plan files, targeting resources, detecting drift, and using plan in CI/CD.

6

terraform apply

terraform apply in depth. Reviewing the plan, auto-approve for CI/CD, applying saved plan files, parallelism, and handling apply errors safely.

7

terraform destroy

terraform destroy safely. Partial destroys with -target, reading the destroy plan, and when to decommission instead. Plus fmt and validate.

8

Terraform Variables and Outputs

How data flows through Terraform. Input variables, local values and outputs, where each belongs, precedence rules, and how to handle secrets safely.

9

Terraform Input Variables

Terraform input variables in depth. Types, defaults, validation rules, tfvars files, CLI flags, environment variables and sensitive values.

10

Terraform Local Values

How Terraform local values work, when to use locals instead of variables or data sources, and how to simplify repetitive expressions.

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

Why Terraform keeps state, what lives in it, how remote backends and locking make teamwork safe, and the state commands that get you out of trouble.

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

What modules are, when to create one, how to design a good interface, versioning and sourcing, and how to move resources into modules without recreating them.

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

How Terraform creates multiple resources from one block. Why count uses positional identity, why that destroys things, and when each meta-argument is correct.

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

The expression language behind Terraform configurations. Types, for expressions, conditionals, the function categories that matter, and how to test them safely.

24

Terraform String Functions

Terraform string interpolation and formatting. Replacements, regex helpers, templatefile, conditionals and other string expressions.

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

Terraform against AWS in practice. Provider configuration, authentication without long-lived keys, multi-account patterns, and tagging.

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.