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.
As your Terraform projects grow, copy-pasting the same VPC, IAM, EC2, or S3 configuration again and again quickly becomes difficult to maintain. Terraform modules solve that problem by letting you package infrastructure code into reusable building blocks.
Every Terraform project already starts as a module—the root module. When that root module calls other directories or Registry packages, those become child modules. This makes it possible to standardize common infrastructure patterns, share them across teams, and keep large configurations easier to understand.
This section covers two practical skills:
| Topic | Description | Link |
|---|---|---|
| Using Modules | Learn how to consume local modules and Registry modules, pass inputs, pin versions, and read module outputs safely. | Learn to use modules |
| Writing Modules | Learn how to structure your own reusable modules with main.tf, variables.tf, outputs.tf, and clear interfaces. | Learn to write modules |
A helpful way to think about modules is this:
- resources create individual infrastructure objects
- modules group related resources into reusable patterns
- inputs customize a module
- outputs expose useful results back to the caller
Once you understand modules, Terraform code becomes much easier to scale. Instead of repeating infrastructure definitions, you can design reusable patterns for networking, compute, storage, and platform services.
Start with Using Terraform Modules →