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.