Last Updated on August 11, 2025 by Arnav Sharma
Terraform, a product by HashiCorp, has revolutionized the concept of “Infrastructure as Code” (IaC). At the heart of Terraform lies the concept of a “module.” A Terraform module is a reusable set of Terraform code that abstracts a piece of infrastructure. Instead of writing repetitive Terraform configurations for similar infrastructure setups, users can create a module once and reuse it across different projects. The root module is the entry point, and from there, one can use child modules to further configure and deploy specific AWS resources like EC2 instances and security groups. These modules can be stored in a Git repository, such as GitHub, allowing for version control and collaboration. With input variables, you can customize the module for different environments, and the module output can be used to pass information to another module or the root module. By adhering to best practices, storing modules in the Terraform Registry, and ensuring proper syntax and security measures, Terraform modules can greatly simplify and streamline your infrastructure deployment process.
In every Terraform project, the power of modularity is evident. A Terraform module is a set of Terraform configuration files bundled together, allowing developers to create reusable infrastructure with ease. Think of it as a building block in your infrastructure code. While you can write single Terraform configurations for specific tasks, using modules in Terraform lets you group these configurations, making them more manageable and scalable. There are various sources from which modules can be utilized. You can use local modules stored in your module directory or remote modules from the Terraform Cloud. For those who prefer a broader community-driven approach, modules from the Terraform Registry, both public and private, offer a plethora of pre-written infrastructure solutions. These published modules adhere to module best practices and come with code examples, simplifying the process of developing modules. If you’re using Terraform Enterprise, the integration is even smoother. The parent module can refer to this child module using the same syntax, and Terraform will automatically handle the intricacies. Whether you’re using the AWS provider or any other, Terraform keeps track of the state and relationships, ensuring that your complex infrastructure remains consistent. For those new to this open-source infrastructure as code tool, creating your first module might seem daunting, but with resources like Terraform’s configuration language and the vast community writing Terraform modules, the journey becomes much more navigable.
Terraform Modules
Let’s say we have three applications (1, 2 and 3) with three different environments as shown below:

Now, each application have its own resource requirements and will need a lot of Terraform coding.
Hence we use Terraform Modules.

What we can do is create a Modules Directory with four required resources and then consume the same
set of code for all the three apps and three different environments:

This is how it will look:

Instead of writing code for VM for each app or having inconsistencies in the IaC deployments, we use modules.
I help organisations secure their cloud infrastructure and stay ahead of evolving cyber threats. Microsoft MVP and Certified Trainer, author of Mastering Azure Security, and founder of arnav.au — a platform for practical Cloud, Cybersecurity, DevOps and AI content.
Frequently Asked Questions
A Terraform module is a reusable set of Terraform configuration files that abstracts a piece of infrastructure, allowing you to create it once and reuse it across different projects. Instead of writing repetitive code for similar infrastructure setups, modules help you avoid inconsistencies, reduce code duplication, and make your infrastructure deployments more manageable and scalable.
You can use local modules stored in your module directory, remote modules from Terraform Cloud, or modules from the Terraform Registry (both public and private). The Terraform Registry offers pre-written infrastructure solutions that adhere to best practices and come with code examples, making it easier to develop and deploy modules.
You can customize modules for different environments using input variables, which allow you to pass different values to the module based on your specific needs. The module outputs can also be used to pass information to another module or the root module, enabling flexible and environment-specific configurations.
The root module is the entry point of your Terraform configuration, while child modules are referenced from the root module to configure and deploy specific resources. The parent module can refer to child modules using the same syntax, and Terraform automatically handles the relationships and state management between them.
Yes, Terraform modules can be stored in Git repositories such as GitHub, allowing for version control and collaboration among team members. This practice is recommended as part of Terraform best practices and helps ensure that your infrastructure code is properly tracked, versioned, and accessible to your team.