Terraform Roadmap for Beginners (2026)
A free Terraform roadmap for beginners: HCL, providers, variables, state in S3, modules, testing, security scans and CI/CD, with an AWS project per step.
Level: Beginner · Time: 3–4 months at ~6 h/week · Updated October 2026 by Ali Bashir
Who this roadmap is for
Beginners, sysadmins and developers who want to stop clicking in the cloud console and build infrastructure as code. You need a free AWS account and basic terminal and Git skills.
By the end you can
- Build and destroy AWS infrastructure with Terraform
- Write reusable modules with variables and outputs
- Keep state safe in S3 with native locking
- Test and security-scan Terraform before it ships
- Run plan on pull requests and apply on merge from CI
Step 1: What IaC is and why
Before you learn any commands, understand what problem infrastructure as code solves: servers and networks that are written down, reviewed and rebuilt from files instead of clicked together by hand. This also helps you pick the right tool and explain the choice in an interview.
Time: 1 week. Skip if you can explain declarative IaC, why teams keep it in Git, and how Terraform differs from OpenTofu, Pulumi and CloudFormation.
Topics
- What is IaC?
- Infrastructure as code (IaC) means you describe servers, networks and databases in text files instead of creating them by clicking in a web console. The files can be reviewed, shared and run again, so you can rebuild the same setup in minutes and see who changed what. HashiCorp: What is infrastructure as code? Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 1: Evolution of Cloud + Infrastructure as Code) Video: What is Infrastructure as Code?
- Declarative vs imperative
- Imperative tools are step-by-step instructions ("create a server, then add a disk"). Declarative tools like Terraform let you describe the end result ("there should be one server with one disk") and the tool works out the steps. Declarative code is easier to re-run safely because it only changes what is different. Terraform: How Terraform works Course: Terraform explained in 15 mins | Terraform Tutorial for Beginners (Declarative vs Imperative) Video: Declarative vs Imperative | Quick Bites of Cloud Engineering
- Git for IaC
- Your Terraform files live in a Git repository, just like application code. Git gives you history, pull requests for review, and an easy way to roll back a bad change, so learn basic commit, branch and merge before you write much Terraform. Pro Git: About version control Video: How Git Works: Explained in 4 Minutes
- Terraform
- Terraform, made by HashiCorp (part of IBM since 2025), is one of the most widely used IaC tools. You write files in a language called HCL, and Terraform talks to AWS, Azure, GitHub and hundreds of other services through plugins called providers. Since 2023 it uses the Business Source Licence (BSL): free to use for your own infrastructure, but not open source. One tool and one workflow work across many clouds. Terraform: What is Terraform? Terraform: Use cases Course: Terraform explained in 15 mins | Terraform Tutorial for Beginners (What is Terraform? What is infrastructure provisioning?) Video: Terraform in 100 Seconds
- OpenTofu (alternative)
- OpenTofu is a free, open-source fork of Terraform, now part of the CNCF (Cloud Native Computing Foundation), created after HashiCorp changed Terraform's licence in 2023. It uses the same HCL language and almost the same commands (tofu instead of terraform). An alternative to Terraform; pick one, since what you learn here works in both. OpenTofu docs: Introduction OpenTofu: Migrating from Terraform Video: What is OpenTofu ? Explained with Demo
- Pulumi (alternative)
- Pulumi lets you write infrastructure in normal programming languages like Python, TypeScript or Go instead of HCL. It suits teams that prefer loops and functions from a language they already know. An alternative to Terraform; pick one. Pulumi docs: Concepts Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 1: Evolution of Cloud + Infrastructure as Code) Video: Pulumi in Three Minutes
- AWS CloudFormation (alternative)
- CloudFormation is AWS's own IaC service, using YAML or JSON templates that AWS deploys as "stacks". It only works for AWS, but it needs no state file and you will see it in many AWS guides. An alternative to Terraform if you only use AWS; pick one. AWS docs: What is CloudFormation? Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 1: Evolution of Cloud + Infrastructure as Code) Video: AWS CloudFormation for Beginners
- Provisioning vs configuration (optional)
- Terraform provisions infrastructure: it creates the server, network and database. Configuration tools like Ansible then set up what runs inside the server, such as packages and files. Many teams use both, so it helps to know where one stops and the other starts. Red Hat: What is configuration management? Course: Terraform explained in 15 mins | Terraform Tutorial for Beginners (Terraform vs Ansible) Video: Ansible vs. Terraform: What's the difference?
Project: IaC tool comparison note
Create a GitHub repo for this roadmap and write a one-page README comparing Terraform, OpenTofu, Pulumi and CloudFormation: language, licence, clouds supported and who uses each. End with which one you picked and why. You will add every project from this roadmap to the same repo.
Common mistakes
- Fixing resources by hand in the cloud console. Manual changes create drift, where real infrastructure no longer matches your code. Make every change in code and apply it through Terraform.
- Keeping Terraform code outside version control. Put all code in Git from day one so every change is reviewed and can be undone. Add .terraform/, *.tfstate and secret .tfvars files to .gitignore.
- Using Terraform to configure software inside servers. Terraform is best at creating infrastructure (provisioning). Use cloud-init, Ansible or container images to set up what runs inside the server (configuration).
You're ready to move on when you can
- Explain infrastructure as code to a friend in two sentences
- Say the difference between declarative and imperative tools
- Explain why OpenTofu exists and how it relates to Terraform
- Name one job Terraform does and one job Ansible does
Step 2: Install and the core workflow
Every Terraform project, from a single bucket to a whole company, uses the same loop: init, plan, apply and, when you are done, destroy. Learn it on a free AWS account now and every later step is just more of the same.
Time: 1–2 weeks. Skip if you can install Terraform, connect it to AWS, and run init, plan, apply and destroy while explaining every line of the plan.
Topics
- Installing Terraform
- Terraform is a single program you download for Windows, macOS or Linux, or install with a package manager like Homebrew, Chocolatey or apt. Check it works with terraform -version, and add the official VS Code extension for colour and autocomplete. Terraform: Install Tutorial: Install Terraform Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 2 Demo) Video: How to Install Terraform on Windows | Hands-On Tutorial | Terraform Tutorial for Beginners
- AWS CLI & credentials
- Terraform needs permission to create things in your AWS account. Install the AWS CLI (command line interface) and log in with aws configure sso or a profile, and Terraform picks up the same credentials. Never paste access keys into your .tf files. AWS CLI: Install AWS CLI: Configuration and credentials Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 2 Demo) Video: AWS CLI Tutorial | Learn to run AWS CLI commands in 10 minutes
- terraform init
- terraform init prepares a folder for Terraform: it downloads the providers your code needs and sets up where state is stored. Run it first in any new project, and again whenever you add a provider, module or backend. Terraform CLI: init Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Learn about the terraform init command (Lightboard)
- terraform plan
- terraform plan compares your code with what really exists and shows what it would create, change or destroy, without touching anything. It is a free safety check, so run it before every apply and read it properly. Terraform CLI: plan Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Terraform Plan and Apply: Beginner’s Guide
- terraform apply
- terraform apply makes the changes from the plan: it calls the cloud APIs, waits for resources to be ready, and saves the results to state. It asks you to type yes first, which is your last chance to stop a mistake. Terraform CLI: apply Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Terraform - Using the terraform apply Command (Lightboard) My short: What Terraform Apply Actually Does (4 Steps)
- terraform destroy
- terraform destroy deletes everything that this configuration manages. It is great for cleaning up practice labs so you do not pay for idle resources, and dangerous if you run it in the wrong folder or account, so always check which workspace and account you are in. Terraform CLI: destroy Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Terraform - Using the terraform destroy Command My short: This Terraform Command Can Delete Production
- Reading plan output
- Plan output uses symbols: + means create, ~ means update in place, - means destroy, -/+ means destroy and then create a replacement, and +/- means create the replacement first and then destroy the old one (create_before_destroy). Learn to spot "forces replacement" and the summary line at the bottom, because a surprise replace can delete a database. Tutorial: Create infrastructure Terraform CLI: show Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Plan and Apply)
- Dependency lock file
- The .terraform.lock.hcl file records the exact provider versions init picked. Commit it to Git so your teammates and your pipeline use the same versions, and upgrade on purpose with terraform init -upgrade. Terraform: Dependency lock file Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: What is .terraform.lock.hcl? | Terraform Lock File Explained
- Version managers (tfenv) (optional)
- Different projects may need different Terraform versions. Tools like tfenv let you install several versions and switch between them per folder, which saves you from "works on my machine" problems. tfenv on GitHub Video: Quick Tech - tfenv
Project: Your first S3 bucket
In a practice AWS account (new accounts get Free plan credits), write a main.tf that creates one private S3 bucket with tags. Run init, plan, apply, change a tag and read the update plan, then destroy everything. Save the plan output in your README with notes on what each symbol means.
Common mistakes
- Running terraform apply without reading the plan first. Read every line of the plan, especially resources marked to destroy or replace (-/+). In automation, save the plan with -out=tfplan and apply exactly that file.
- Using long-lived root account access keys on your laptop. Create an IAM user or SSO role with limited permissions and use aws sso login or named profiles. Never use the root account for daily work.
- Leaving the .terraform.lock.hcl file out of Git. The lock file pins exact provider versions so everyone gets the same build. Commit it, and update it on purpose with terraform init -upgrade.
You're ready to move on when you can
- Install Terraform and connect it to AWS without hardcoded keys
- Run init, plan, apply and destroy on your own
- Explain what +, ~ and -/+ mean in a plan
- Explain why the lock file is committed to Git
Step 3: HCL, providers and resources
HCL is the language you will read and write every day, and providers and resources are its main building blocks. Once you can read any resource block and find its options in the docs, you can build almost anything on AWS.
Time: 2 weeks. Skip if you can write resources and data sources from the provider docs, pin provider versions, and explain how Terraform orders resources.
Topics
- HCL syntax
- HCL (HashiCorp Configuration Language) is made of blocks with a type and labels, holding arguments like name = "value". It also has comments, strings, numbers, lists and maps. It is designed to be easy for people to read, so most files look like simple settings. Terraform: Configuration syntax Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Language) Video: Day 2: Master HCL syntax and Learn how to write Terraform Code
- Files & folder layout
- Terraform reads every .tf file in a folder as one configuration, so the file names are for people. Most projects split code into main.tf, variables.tf, outputs.tf and providers.tf, and follow the official style guide so others can find things fast. Terraform: Files and directories Terraform: Style guide Course: Terraform Course - Automate your AWS cloud infrastructure (Terraform Files) Video: How To Structure Your Terraform Projects (Don't Make This Mistake)
- Providers
- A provider is a plugin that teaches Terraform how to talk to one platform, such as AWS, Azure, GitHub or Cloudflare. You declare it in your code, init downloads it, and it adds the resource types you can use. Terraform: Providers Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Providers) Video: Terraform Tutorial | Terraform providers | What is a Terraform provider | Terraform Basics
- AWS provider
- The AWS provider turns your HCL into AWS API calls. You set the Region in a provider block, credentials come from your AWS profile, and default_tags can tag every resource for you. Its Registry page is the reference you will read most. AWS provider docs (Terraform Registry) Tutorial: Get started on AWS Course: Terraform Course - Automate your AWS cloud infrastructure (Terraform Overview) Video: Beginners Tutorial to Terraform with AWS
- Azure & Google providers (alternative)
- If your job uses Azure or Google Cloud, use the azurerm or google provider instead. The HCL, workflow and state work the same way; only the resource names change. An alternative to the AWS provider; pick the cloud you are learning. AzureRM provider docs Google provider docs Video: Beginners Tutorial to Terraform with Azure
- Provider versions
- The required_providers block says which providers you need and which versions are allowed, for example ~> 6.0. Pinning versions stops a surprise upgrade from changing how your code behaves. Terraform: Provider requirements Terraform: Version constraints Video: 3.3 Learn Terraform - Lock and Upgrade Provider Versions
- Resources
- A resource block describes one thing you want to exist, such as an EC2 instance or an S3 bucket. It has a type, a local name and arguments, and you refer to it elsewhere as type.name.attribute, for example aws_s3_bucket.logs.arn. Terraform: Resource blocks Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Terraform Basics: Resource Blocks
- Data sources
- A data block reads information that already exists without managing it, such as the latest Amazon Linux image ID or your account ID. Use data sources instead of copying IDs by hand, so your code stays correct in every Region and account. Terraform: Data sources Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Variables and Data) Video: Data Sources | Terraform Tutorial | #10
- Resource dependencies
- When one resource refers to another, Terraform knows to create them in the right order and runs the rest in parallel. Only add depends_on when there is a hidden link Terraform cannot see from your references. Terraform: Resource dependencies Terraform: depends_on Course: Terraform Course - Automate your AWS cloud infrastructure (Referencing Resources) Video: Resource Exports & Dependencies | Terraform Tutorial | #5
- Lifecycle rules
- The lifecycle block changes how Terraform handles a resource. prevent_destroy blocks accidental deletion of things like databases, create_before_destroy avoids downtime on replacement, and ignore_changes stops fights with values set outside Terraform. Terraform: lifecycle Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Meta Arguments) Video: How to use the terraform lifecycle block to protect your resources
- Provisioners (optional)
- Provisioners run scripts on a machine after Terraform creates it. HashiCorp calls them a last resort because Terraform cannot track what the script did; prefer user_data, cloud-init or a pre-built image. Terraform: Provisioners Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Provisioners) Video: What are terraform Provisioners? - Part 7
Project: A web server on EC2
Write Terraform that looks up the latest Amazon Linux image with a data source, then creates a security group allowing only HTTP and an EC2 instance (a free-tier eligible size such as t3.micro) that installs a web server with user_data. Pin your provider version, apply, open the page in a browser, then destroy it.
Common mistakes
- Leaving provider versions unpinned in required_providers. A new major provider version can break your code on the next init. Set a constraint like version = "~> 6.0" and upgrade deliberately.
- Renaming a resource and accidentally destroying the real one. Terraform treats a new resource address as a new resource and deletes the old one. Add a moved block from the old name to the new name before you apply.
- Relying on provisioners to set up servers. Provisioners are a last resort and failures leave resources half-configured. Use user_data with cloud-init, or bake a ready image instead.
You're ready to move on when you can
- Read an unfamiliar resource block and find its arguments in the Registry
- Use a data source instead of a hardcoded ID
- Pin a provider version with required_providers
- Protect an important resource with prevent_destroy
Step 4: Variables, outputs and expressions
Hardcoded values make code you can only use once. Variables, outputs, loops and functions let one configuration build many similar things and work for dev and prod without copy-paste.
Time: 2 weeks. Skip if you can build several resources from one map with for_each, use typed variables with validation, and pass values out with outputs.
Topics
- Input variables
- Variables are the inputs to your configuration, like function parameters. You declare them in a variable block with a type, description and optional default, then use them as var.name, so the same code can use different values. Terraform: Input variables Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 4: Variables and Outputs) Video: Learn how to use Terraform variables
- Types & type constraints
- Terraform values have types: string, number, bool, list, map, set and object. Setting a type on a variable catches mistakes early, for example passing a single name where a list of names was expected. Terraform: Type constraints Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Resources and Complex Types) Video: Terraform Input Variable (string, number, bool, list, map...) | How to use Terraform Input Variable
- .tfvars files
- A .tfvars file holds the values for your variables, such as dev.tfvars and prod.tfvars. Terraform loads terraform.tfvars automatically and others with -var-file, which keeps values out of the code. Do not commit files that contain secrets. Terraform: Assign values to variables Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 4: Variables and Outputs) Video: What is a tfvars file in Terraform? | Manage Variables & Multiple Environments
- Outputs
- Output blocks print useful values after apply, like a server IP or a website URL. They are also how a module hands values back to the code that called it. Mark outputs sensitive = true if they hold secrets. Terraform: Output values Course: Terraform Course - Automate your AWS cloud infrastructure (Terraform Output) Video: Learn Terraform Outputs in 4 Minutes
- Locals
- Locals are named values you calculate once inside a configuration, such as a name prefix or a shared set of tags. Use them to avoid repeating the same expression in many places; use variables for anything a user should change. Terraform: Local values Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 4: Variables and Outputs) Video: Local Values | Terraform Tutorial | #8
- Expressions & references
- Expressions are how values are built and connected: references like aws_vpc.main.id, string templates like "${var.env}-web", and operators. Learning to read them is key to understanding anyone else's Terraform. Terraform: References to values Terraform: Strings and templates Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Expressions) Video: Expressions | Terraform Tutorial | #12
- Built-in functions
- Terraform has built-in functions for text, numbers, lists, maps, files and networks, such as lower(), merge(), lookup() and cidrsubnet(). You cannot write your own functions in HCL, so try ideas in terraform console before using them. Terraform: Functions Terraform CLI: console Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Built in Functions) Video: Terraform Basics - Functions
- count
- The count meta-argument creates several copies of a resource, numbered from 0. It is perfect for "make 3 of these" or for turning a resource on or off with count = var.enabled ? 1 : 0. Terraform: count Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Meta Arguments) Video: Terraform Count Meta Argument and Count Index with example | count vs for_each demo tutorial
- for_each
- for_each creates one copy of a resource for each item in a map or set, named by its key instead of a number. Removing one item only deletes that copy, which makes it safer than count for lists that change. Terraform: for_each Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Meta Arguments) Video: Terraform for loop, for_each loop and count - Part 6
- for expressions
- A for expression builds a new list or map from another one, like [for s in var.subnets : s.id]. You can also filter with if, which makes it easy to reshape data before passing it to for_each. Terraform: for expressions Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Expressions) Video: Terraform for loop, for_each loop and count - Part 6
- Conditional expressions
- The conditional expression condition ? a : b picks a value based on a true or false test, such as a bigger instance size only in prod. Keep conditions simple so the plan stays easy to read. Terraform: Conditional expressions Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Expressions) Video: Conditional Expressions in Terraform | Terraform Conditional Expressions Tutorial
- Dynamic blocks (optional)
- A dynamic block repeats a nested block, such as many ingress rules inside one security group, from a list or map. It is handy but can make code hard to read, so use it only when the repetition is real. Terraform: Dynamic blocks Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Expressions) Video: Dynamic Blocks | Terraform Tutorial | #13
Project: One config, many buckets
Refactor your earlier code so a map variable describes several S3 buckets (name, versioning on or off) and for_each creates them all. Add locals for shared tags, outputs for every bucket ARN, and separate dev.tfvars and prod.tfvars files that change the bucket names.
Common mistakes
- Using count for a list that may change order. Removing one item from a count list shifts every index and can recreate the rest. Use for_each with a map or set so each resource has a stable key.
- Hardcoding values that differ between environments. Move region, instance size and names into input variables with types and descriptions. Set them per environment in .tfvars files.
- Thinking sensitive = true keeps secrets out of state. sensitive only hides values in plan and CLI output; they are still stored in plain text in state. Protect the state file and prefer ephemeral values or a secrets manager where possible.
You're ready to move on when you can
- Declare a typed variable with a description and default
- Explain why for_each is safer than count for a changing list
- Use a function and a for expression in terraform console
- Pass different values with two .tfvars files
Step 5: State: local and remote
State is how Terraform remembers what it built, and most painful Terraform incidents are state problems. Moving state to S3 with locking is the step that makes Terraform safe for a team or a pipeline.
Time: 2 weeks. Skip if you keep state in a locked, encrypted S3 backend and can safely rename or move resources without destroying them.
Topics
- What is state?
- The state file (terraform.tfstate) maps each resource in your code to the real object in the cloud, with its ID and attributes. Terraform uses it to work out what to change. Never edit it by hand, and treat it as secret, because it can contain passwords in plain text. Terraform: State Terraform: Sensitive data in state Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Learn Terraform State in 10 Minutes
- Local state
- By default state is saved as a file in your project folder. That is fine while learning alone, but it is lost if your laptop dies and cannot be shared, so it should never be committed to Git. Terraform: local backend Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Backends) Video: What is Terraform "state"?
- Remote backends
- A backend decides where state is stored. Remote backends keep it in shared storage, such as S3, Azure Blob Storage or HCP Terraform, so your team and your pipeline all work from the same copy. Terraform: Backends Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Terraform remote state backends explained | Appsbroker Academy
- S3 backend
- The S3 backend stores state in an S3 bucket. Turn on bucket versioning so you can recover an old state, encryption to protect secrets, and block public access. Create the bucket once, outside the configuration that uses it. Terraform: S3 backend Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3 Demo) Video: 4/30 - Terraform State file management with AWS S3 | Remote Backend
- State locking
- Locking stops two people or pipelines from changing the same state at the same time, which could corrupt it. The S3 backend now locks natively with use_lockfile = true; the older DynamoDB table method is deprecated. Terraform: State locking Terraform: S3 backend state locking Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 3: Basic Terraform Usage) Video: Terraform state locking with new use_lockfile native AWS S3 bucket locking mechanism
- HCP Terraform (alternative)
- HCP Terraform (formerly Terraform Cloud) is HashiCorp's hosted service that stores state, locks it, and can run plan and apply for you, with a free tier for small teams. An alternative to an S3 backend; pick one. HCP Terraform docs Tutorial: Get started with HCP Terraform Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Cloud) Video: What is Terraform Cloud?
- State commands
- terraform state list, show, mv and rm let you look inside state and fix it safely without editing the JSON. Use them carefully, take a backup first, and run plan afterwards to check nothing unexpected will happen. Terraform CLI: state Terraform CLI: state list Course: Terraform Course - Automate your AWS cloud infrastructure (Terraform State Commands) Video: Mastering Terraform State Management: Essential Commands Explained (push, pull, list, show, mv, rm)
- Refactoring with moved (optional)
- If you rename a resource or move it into a module, Terraform thinks it is a new resource and plans to destroy the old one. A moved block tells Terraform the old and new addresses are the same thing, so nothing is deleted. Terraform: Refactoring with moved blocks Video: Using Moved Blocks in Terraform
- terraform_remote_state (optional)
- The terraform_remote_state data source reads outputs from another configuration's state, for example a VPC ID from your network project. It works, but it needs read access to the whole state, so many teams prefer data sources or a parameter store. Terraform: terraform_remote_state Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Backends) Video: What's Wrong With The Terraform Remote State Data Source?
Project: Move your state to S3
Create a versioned, encrypted, private S3 bucket for state, then add an S3 backend with use_lockfile = true to your project and migrate with terraform init -migrate-state. To see the lock, run terraform apply in one terminal and leave it waiting at the yes prompt, then run plan in a second terminal and read the lock error. Finally rename a resource using a moved block and confirm the plan shows no destroy.
Common mistakes
- Keeping the state file only on one laptop. If the laptop is lost, Terraform no longer knows what it manages. Use a remote backend such as S3 with versioning and encryption enabled from the start.
- Still creating a DynamoDB table just for state locking. The S3 backend now supports native locking with use_lockfile = true, and DynamoDB locking is deprecated. Turn on use_lockfile so two people cannot apply at once.
- Editing the state file by hand to fix a problem. A bad manual edit can make Terraform lose track of real resources. Use terraform state mv, state rm, moved blocks or import blocks instead, and back up state first.
You're ready to move on when you can
- Explain what the state file stores and why it is sensitive
- Set up an S3 backend with native locking
- Use terraform state list and show to inspect resources
- Rename a resource without destroying it
Step 6: Modules, workspaces and environments
Real projects have dev, staging and prod that must look the same but stay separate. Modules let you write a piece of infrastructure once, and a clear environment layout keeps a dev change from ever touching prod.
Time: 2 weeks. Skip if you have written a versioned module, used a Registry module, and run separate dev and prod environments with separate state.
Topics
- What is a module?
- A module is a folder of Terraform files with inputs (variables) and outputs. Every project is already a root module; you call child modules with a module block to reuse the same code, like a function you can call many times. Terraform: Modules Terraform: Module blocks Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 6: Project Organization + Modules) Video: Terraform Basics: Modules
- Terraform Registry
- The Terraform Registry is the public library of providers and modules. Before writing something big, like a VPC or an EKS cluster, check for a well-maintained module there, and read its inputs, outputs and open issues first. Terraform Registry Terraform: Registry docs Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Modules) Video: Learn How To Use Modules on the Terraform Registry
- Using registry modules
- Calling a module like terraform-aws-modules/vpc/aws can build dozens of resources from a few lines. Pin its version, pass only the inputs you need, and run plan to see exactly what it will create. Terraform: Module sources terraform-aws-modules VPC module Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 6: Project Organization + Modules) Video: How to Create AWS VPC with Terraform Modules
- Writing your own module
- A good module does one job, has clear variable names with descriptions, sensible defaults and useful outputs. Start by moving code you have copied twice into a modules/ folder, then call it from each environment. Terraform: Creating modules Tutorial: Build and use a local module Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 6 Demo) Video: Creating a module in Terraform - Getting started with Terraform Modules (part 1)
- Module versioning
- Store shared modules in Git or a registry and tag releases like v1.2.0. Callers pin a version, so you can improve the module without breaking every environment at once, and upgrade one environment at a time. Terraform: Module version constraint Terraform: Publishing modules Video: Terraform modules on Github with versioning
- Folder per environment
- The simplest safe layout is one folder per environment (envs/dev, envs/prod), each with its own backend and tfvars, all calling the same modules. A mistake in dev cannot touch prod state, and the difference between environments is easy to see. Tutorial: Separate development and production environments Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 7: Managing Multiple Environments) Video: Managing Multiple Environments with Terraform
- Workspaces
- CLI workspaces give one configuration several separate state files, switched with terraform workspace select. They are quick for temporary copies, but HashiCorp warns they are not ideal for separating dev and prod, which usually need different accounts and settings. Terraform: Workspaces Terraform CLI: workspace Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Workspaces) Video: Workspaces | Terraform Tutorial | #16
- Terragrunt (alternative)
- Terragrunt is a thin wrapper around Terraform and OpenTofu that keeps backend and provider settings DRY (Don't Repeat Yourself) across many environments and runs many modules in order. An alternative to plain folder-per-environment; pick one when you have many accounts. Terragrunt docs Video: Getting started with Terragrunt
- Module composition (optional)
- Composition means building bigger systems from small modules that pass outputs to each other, such as a network module feeding a database module. Keeping modules small and flat is easier to test and change than deep module trees. Terraform: Module composition Video: How to Master Terraform Modules in 4 Steps
Project: Dev and prod from one module
Write a small module that builds a VPC (use the Registry VPC module inside it or write your own) plus one security group. Call it from envs/dev and envs/prod folders, each with its own S3 state key and tfvars. Tag the module v1.0.0 in Git and pin it from both environments.
Common mistakes
- Referencing modules without pinning a version. An unpinned module can change under you on the next init. Set version = "~> 6.0" (the module's current major version) for registry modules, or ?ref=v1.2.0 for Git sources.
- Using workspaces to separate production from development. Workspaces share one backend and the same credentials, so a wrong workspace selection can hit production. Use separate folders or separate state per environment, ideally in separate accounts.
- Wrapping a single resource in its own module. A thin wrapper adds inputs to maintain without adding value. Create a module when it groups several resources that are always used together.
You're ready to move on when you can
- Turn repeated code into a module with inputs and outputs
- Use and pin a Terraform Registry module
- Keep dev and prod in separate state
- Explain when workspaces are and are not a good idea
Step 7: Testing, validation and security
A typo in Terraform can open a database to the internet. Formatting, validation, linting, tests and security scanners catch most mistakes in seconds on your laptop, long before anything reaches the cloud.
Time: 2 weeks. Skip if your repo runs fmt, validate, TFLint, terraform test and Checkov or Trivy automatically, and you can fix what they report.
Topics
- terraform fmt
- terraform fmt rewrites your files into the standard Terraform style: indentation, spacing and aligned equals signs. Run it before every commit (or use -check in CI) so reviews focus on real changes, not whitespace. Terraform CLI: fmt Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 8: Testing Terraform Code) Video: 1.5 Learn Terraform the Clean Way with Formatting and Validation
- terraform validate
- terraform validate checks that your configuration is correct HCL with valid references and argument names, without contacting any cloud. It is fast and free, so it is the first check in any pipeline. Terraform CLI: validate Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 8: Testing Terraform Code) Video: How to Format and Validate Terraform Code | terraform fmt | terraform validate
- TFLint
- TFLint is a linter that finds problems validate misses, such as invalid EC2 instance types, unused variables and missing version pins. Add the AWS ruleset plugin to catch mistakes that would only fail at apply time. TFLint on GitHub TFLint AWS ruleset Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 8: Testing Terraform Code) Video: Quick Tech - TFlint
- Custom conditions
- Variable validation blocks reject bad input with a clear error, like an environment name that is not dev or prod. Preconditions, postconditions and check blocks test assumptions about resources during plan and apply. Terraform: Custom conditions Terraform: Checks Video: Using Precondition and Postcondition Blocks in Terraform
- terraform test
- terraform test is the built-in testing framework. You write .tftest.hcl files with run blocks and assertions, and it can test against a plan, real short-lived resources, or mocked providers so you do not pay for cloud resources. Terraform: Tests Terraform CLI: test Video: Validate your code with the Terraform test framework
- Checkov
- Checkov is a free scanner that checks Terraform for security mistakes, like public S3 buckets, open security groups or missing encryption, before you deploy. Run it locally and in pull requests, and fix or document each finding. Checkov docs: What is Checkov Checkov docs: Terraform scanning Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 8: Testing Terraform Code) Video: What is Checkov? Benefits, Key Features, and Examples
- Trivy (alternative)
- Trivy, from Aqua Security, scans Terraform for misconfigurations and also scans container images and dependencies, so one tool covers many jobs. It replaced the older tfsec tool. An alternative to Checkov; pick one. Trivy docs: Misconfiguration scanning Video: Trivy Terraform Plan Misconfiguration Scanning -- tfplan.json
- Pre-commit hooks (optional)
- pre-commit runs tools like terraform fmt, validate, TFLint and Checkov automatically every time you commit. The pre-commit-terraform project bundles ready-made hooks, so bad code never even reaches your pull request. pre-commit pre-commit-terraform on GitHub Video: Quick Tech - pre-commit-terraform
- Terratest (optional)
- Terratest is a Go library that deploys your Terraform into a real account, checks that it works (for example, the website answers), then destroys it. It is powerful but slower and needs some Go, so most beginners start with terraform test. Terratest docs Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 8 Demo) Video: 7.7 Learn Terraform - Automated Testing with Terratest
- Policy as code (optional)
- Policy as code means writing rules like "every bucket must be encrypted" as code that checks each plan. Open Policy Agent (OPA) and HashiCorp Sentinel are common choices for teams that need to enforce rules across many projects. OPA docs: Terraform Sentinel docs: Terraform Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Sentinel and Terraform) Video: Using OPA with Terraform - Rego Basics
- Infracost (optional)
- Infracost reads your Terraform and estimates the monthly cloud bill, and can comment the cost difference on pull requests. It helps you catch an expensive instance size or NAT gateway before you pay for it. Infracost docs Video: How to estimate infrastructure cost using infracost
Project: Test and scan your modules
Add a .tftest.hcl file to your VPC module that asserts the CIDR and tags using a plan-only run. Add variable validation for the environment name, set up pre-commit with fmt, validate and TFLint, and run Checkov or Trivy against the repo. Fix or document every high-severity finding in your README.
Common mistakes
- Assuming terraform validate catches every mistake. validate only checks syntax and types, not whether the cloud will accept your values. Add TFLint for provider rules and terraform test or a plan in CI for real checks.
- Skipping security scanning until after deployment. Run Checkov or Trivy on every pull request to catch public buckets, open security groups and missing encryption. Fixing it in code is far cheaper than fixing it live.
- Never checking cost before applying a change. A small change in instance type or count can raise the bill a lot. Run Infracost on pull requests so reviewers see the cost difference.
You're ready to move on when you can
- Explain the difference between fmt, validate and TFLint
- Write a terraform test with at least two assertions
- Reject bad input with a validation block
- Find and fix a security issue reported by Checkov or Trivy
Step 8: CI/CD, drift and best practices
In a team, nobody should run terraform apply from a laptop. A pipeline that plans on every pull request and applies on merge, with tight permissions and drift checks, is how Terraform is run safely in real jobs.
Time: 2–3 weeks. Skip if you run plan on pull requests and apply on merge with OIDC credentials, detect drift on a schedule, and can import resources made by hand.
Topics
- Plan on pull requests
- A GitHub Actions workflow runs fmt, validate and terraform plan on every pull request and posts the plan as a comment. Reviewers then see exactly what will change in the cloud before they approve the code. Tutorial: Automate Terraform with GitHub Actions setup-terraform action Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 9: Developer Workflows and Automation) Video: Automated Terraform Plan and Apply on Every PR (No More Manual Runs)
- Apply on merge
- After review, merging to main triggers terraform apply, ideally of the exact plan that was reviewed. Add a manual approval step for prod using GitHub environments so a person confirms every production change. Tutorial: Running Terraform in automation GitHub docs: Deployment environments Course: Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code) (Part 9 Demo) Video: Deploy to AWS with Terraform within a GitHub Action
- OIDC for AWS
- OIDC (OpenID Connect) lets your pipeline get short-lived AWS credentials by assuming an IAM role, so no access keys are stored in GitHub secrets. Limit the role's trust policy to your repository and branch. GitHub docs: OIDC in AWS AWS: configure-aws-credentials action Video: Securely deploy to AWS with GitHub Actions and OIDC
- Atlantis (alternative)
- Atlantis is a free, self-hosted server that runs Terraform plan and apply from pull request comments, and locks a project while a PR is open. An alternative to GitHub Actions for Terraform; pick one. Atlantis docs Video: Atlantis Walkthrough
- HCP Terraform workflows (alternative)
- HCP Terraform can connect to your Git repo and run speculative plans on pull requests and applies on merge for you, with state, locking and access controls built in. An alternative to building the pipeline yourself; pick one. HCP Terraform: UI and VCS-driven run workflow Tutorial: Automate with HCP Terraform VCS Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Terraform Workflows) Video: Demo: Terraform Cloud + Github VCS
- Drift detection
- Drift is when the real cloud no longer matches your code, usually because someone changed something in the console. Run terraform plan -detailed-exitcode on a schedule: exit code 2 means there are changes. Then either update the code or apply to put things back. terraform plan -refresh-only shows only what changed outside Terraform. Tutorial: Manage resource drift Terraform CLI: refresh-only mode Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Drift) Video: Terraform -refresh-only tutorial | Fixing State drift the right way My short: Deploy Passed, But Production Drifted
- Importing resources
- Most companies have resources that were created by hand. An import block (or terraform import) brings an existing resource under Terraform control, and terraform plan -generate-config-out can write a first draft of the code for you. Terraform: Import Terraform: Generating configuration Course: HashiCorp Terraform Associate Certification Course (003) - Pass the Exam! (Drift) Video: Exploring the Import Block in Terraform 1.5
- State security
- State can hold passwords, keys and every resource ID in your account. Keep it in an encrypted, versioned, private bucket, allow only the pipeline role and a few admins to read it, and never commit it to Git. Terraform: Sensitive data in state AWS: Blocking public access to S3 Video: 8 Terraform Best Practices that will improve your TF workflow immediately
- Least privilege for Terraform
- Least privilege means the role Terraform uses gets only the permissions it needs. Use a read-only role for plan on pull requests and a separate apply role for main, and avoid giving pipelines full AdministratorAccess. AWS IAM: Security best practices AWS IAM: Grant least privilege Video: AWS IAM Core Concepts You NEED to Know
- Secrets in Terraform
- Never put passwords or API keys in .tf or .tfvars files in Git. Mark variables sensitive, read secrets from a service like AWS Secrets Manager, and use ephemeral values or write-only arguments where supported so secrets stay out of state. Terraform: Manage sensitive data AWS Secrets Manager: What is it? Video: How to Manage Secrets in Terraform?
- Reviewing AI-written Terraform (optional)
- AI assistants can write Terraform quickly, but they often invent arguments, skip encryption or give too many permissions. Treat AI output like a junior's pull request: run validate, TFLint and a security scan, and read the plan before anything is applied. Terraform: Style guide My short: AI Wrote Your Terraform. Who Deploys It?
Project: Terraform pipeline with GitHub Actions
Create an IAM role that GitHub Actions can assume with OIDC, then add a workflow that runs fmt, validate, TFLint, Checkov and plan on every pull request and posts the plan as a comment. Apply only on merge to main, with a manual approval for prod. Change a tag by hand in the console and show the scheduled drift check catching it.
Common mistakes
- Storing static AWS access keys as CI secrets. Long-lived keys can leak and keep working until someone revokes them. Use OIDC so the pipeline gets short-lived credentials by assuming an IAM role.
- Giving the Terraform pipeline full administrator access. A broken or malicious change can then do anything in the account. Scope the role to the services it manages, and use a read-only role for plans. With S3 native locking, plan still writes a lock file, so that role also needs s3:PutObject and s3:DeleteObject on the .tflock object.
- Applying AI-written Terraform without checking the plan. AI tools can invent arguments, use outdated syntax or open resources to the internet. Run fmt, validate, a security scan and a human review of the plan before applying.
You're ready to move on when you can
- Run plan on pull requests and apply on merge
- Deploy from CI with OIDC and no stored access keys
- Detect drift and decide whether to fix code or infrastructure
- Import a resource that was created by hand
Capstone project: Production-style AWS environment in Terraform
Build a small but realistic setup: a VPC, a load-balanced web app and a database, written as versioned modules and deployed to separate dev and prod environments with S3 state and native locking. Add terraform test, TFLint and Checkov, and a GitHub Actions pipeline using OIDC that plans on pull requests and applies on merge. Finish with a README showing your architecture diagram, a scheduled drift check, and how you would recover from a bad apply.
Certifications
- HashiCorp Certified: Terraform Associate (004): The standard beginner Terraform cert: a one-hour multiple-choice exam (version 004, tests Terraform 1.12), $70.50, valid for 2 years. Take it after step 6.
- HashiCorp Certified: Terraform Infrastructure Engineer Professional (Professional): The next level after Associate, for engineers with production Terraform experience. HashiCorp says this multiple-choice exam launches in October 2026, so check the page for availability and price. The older hands-on lab exam is now called Terraform Authoring and Operations Advanced.
Frequently asked questions
How long does it take to learn Terraform?
About 3–4 months at 6 hours a week to finish this roadmap from scratch, and you can write useful Terraform after the first 2–3 weeks. If you already know AWS and Git, expect closer to 6–8 weeks.
Should I learn Terraform or OpenTofu?
Learn Terraform first because it is still what most job ads ask for. OpenTofu uses the same language and almost the same commands, so switching later takes an afternoon, not a new course.
Do I need to know AWS before learning Terraform?
Basic AWS helps a lot: you should know what an EC2 instance, S3 bucket, VPC and IAM role are. Terraform only describes cloud resources, so if you do not understand the resource, the code will not make sense either.
Do I need programming skills for Terraform?
No. HCL is a configuration language, closer to a settings file than a programming language. Being comfortable with a terminal, Git and reading documentation matters more than coding.
Is the Terraform Associate certification worth it?
It is a cheap, well-known way to show you understand the basics, and it is often listed in DevOps and cloud job ads. It helps most when paired with public Terraform projects on GitHub, like the ones in this roadmap.
Will learning Terraform cost me money?
Terraform itself is free. The projects here are small enough for the AWS Free plan credits that new accounts get, and if you run terraform destroy after each lab and set a billing alert, your bill should stay at or near zero.