Skip to main content

Terraform Fundamentals

Terraform is an infrastructure-as-code tool for provisioning and changing infrastructure through declarative configuration. You describe the desired result, and Terraform determines the changes required to reach it.

Practice as you read

👉 Launch the official Terraform Sandbox. It comes with Terraform, Docker, LocalStack, and the AWS CLI already set up, so you can try the examples without installing anything.


The Learning Path​

The pages below are arranged in the order that works best for a newcomer. Each stage builds on the one before it.

How to use this guide
  • New to Terraform? Follow the numbers from 1 to 32 in order.
  • Already know the basics? Jump straight to the part you need.
  • Status: ✅ means the page is ready to read. 🚧 means it is planned and coming soon.

The Building Blocks at a Glance​

Every Terraform project is made from the same handful of pieces. This table is a quick map of what each one is for.

Building blockWhat it isExample
ProviderA plugin that lets Terraform talk to a service such as AWSprovider "aws" { ... }
ResourceSomething Terraform creates and managesresource "aws_s3_bucket" "demo" { ... }
Data sourceA read-only lookup of something that already existsdata "aws_vpc" "main" { ... }
VariableAn input value supplied from outside the codevar.region
LocalA named value calculated inside the codelocal.bucket_name
OutputA value shown or shared after applyoutput "bucket_name" { ... }
ModuleA reusable folder of Terraform codemodule "network" { ... }
StateTerraform's record of what it has already builtterraform.tfstate

The workflow in four commands​

terraform init # download the providers your code needs
terraform plan # preview what will change
terraform apply # build it for real
terraform destroy # remove everything when you are done

Part 1: Getting Started​

Install Terraform, give it access to AWS, and run the four commands you will use every day.

#TopicWhat you will learnStatus
1Installing TerraformInstall the Terraform CLI and check that it works✅ Ready
2Connecting Terraform to AWSGive Terraform credentials and a region so it can create real resources✅ Ready
3Terraform Core CommandsThe four commands you use every time: init, plan, apply, destroy✅ Ready

Part 2: Core Concepts​

The ideas that every later page relies on.

#TopicWhat you will learnStatus
4Terraform Safety NetsTags, prevent_destroy, replace vs update, and renaming safely✅ Ready
5Terraform Providers ExplainedWhat providers are, how to pin versions, and how to use several at once✅ Ready
6HCL Syntax BasicsBlocks, arguments, types, and expressions✅ Ready
7Terraform StateWhat the state file is, local vs remote, locking, and drift✅ Ready

Part 3: Reusable and Readable Code​

Stop hardcoding values and start organizing your project.

#TopicWhat you will learnStatus
8Terraform Input VariablesTypes, defaults, validation, and all the ways to set a value✅ Ready
9Terraform OutputsShow and share values after apply✅ Ready
10Terraform Project StructureStandard files, folders, and separating environments✅ Ready
11Terraform LocalsName a value once and reuse it everywhere✅ Ready
12Terraform Data SourcesRead information about things that already exist✅ Ready
13Terraform Resource DependenciesHow Terraform decides the build order, and when to use depends_on✅ Ready

Part 4: Dynamic Code and Meta-Arguments​

Create many resources from one block, and make choices inside your code.

#TopicWhat you will learnStatus
14countCreate several copies of a resource🚧 Coming soon
15for_eachCreate resources from a map or a set, each with its own settings🚧 Coming soon
16Conditional ExpressionsChoose a value with condition ? a : b🚧 Coming soon
17Built-in FunctionsWork with strings, lists, maps, and more🚧 Coming soon
18Lifecycle Meta-ArgumentsControl how Terraform creates, replaces, and protects resources🚧 Coming soon

Part 5: Building AWS Infrastructure​

Put the concepts to work on real AWS services.

#TopicWhat you will learnStatus
19VPCs and SubnetsBuild the network your resources live in🚧 Coming soon
20Security GroupsControl which traffic can reach your resources🚧 Coming soon
21EC2 InstancesLaunch servers into your network🚧 Coming soon
22IAMRoles, policies, and least-privilege access🚧 Coming soon
23SSM Parameters and SecretsKeep configuration and secrets out of your code🚧 Coming soon
24DynamoDBCreate and manage NoSQL tables🚧 Coming soon
25Lambda and SQSRun serverless functions and connect them with queues🚧 Coming soon
Why networking comes before servers

An EC2 instance needs a subnet and a security group to launch into, so VPCs and Subnets (19) and Security Groups (20) come before EC2 Instances (21).


Part 6: Modules​

Package your configuration so it can be reused.

#TopicWhat you will learnStatus
26Using ModulesCall existing modules and pass them values🚧 Coming soon
27Writing ModulesBuild your own reusable modules with inputs and outputs🚧 Coming soon

Part 7: State and Team Workflows​

Work safely as a team and as your state grows.

#TopicWhat you will learnStatus
28Remote State on S3Store state in a shared bucket with locking🚧 Coming soon
29WorkspacesKeep separate state for each environment from one codebase🚧 Coming soon
30Moving and Removing StateRename or stop tracking resources without destroying them🚧 Coming soon
31Import and ReplaceBring existing resources under Terraform, and force a rebuild when needed🚧 Coming soon

Part 8: Quality and Troubleshooting​

Keep your code clean and find problems early.

#TopicWhat you will learnStatus
32fmt, validate, and Debugging DriftFormat and check your code, then find and fix differences between your code and reality🚧 Coming soon

More to Explore​

Topics that pair well with everything above and may be added later:

  • dynamic blocks for generating repeated nested settings
  • terraform console for testing expressions interactively
  • Security best practices for secrets and state
  • Running Terraform in a CI/CD pipeline
  • Writing automated tests with terraform test

Q&A