Creating Reusable Modules
Learn to author your own Terraform modules, defining inputs, outputs, and resources to build modular and flexible configurations.
Build Your Own Terraform Modules
In the previous lesson, we learned about using existing Terraform modules. Now, let's dive into creating your very own reusable modules!
Authoring modules helps you encapsulate common infrastructure patterns, making your configurations cleaner, more consistent, and easier to maintain.
Organizing Your Module Files
A Terraform module is essentially a collection of .tf files stored in a dedicated directory.
At its simplest, a module directory will contain:
variables.tf: Defines input variables for the module.main.tf: Contains the actual resource declarations.outputs.tf: Defines output values from the module.
You can also include versions.tf for provider requirements and README.md for documentation.
All lessons in this course
- Introduction to Terraform Modules
- Creating Reusable Modules
- Using Workspaces for Environments
- Publishing Modules to a Registry