๐ง What Is a Terraform Module? A Terraform module is a reusable, self-contained package of Terraform code.
A module typically contains: main.tf โ resources variables.tf โ inputs outputs.tf โ exposed values Terraform treats every directory as a module.
Modules allow you to: Encapsulate complexity Enforce standards Reuse infrastructure patterns Scale cleanly across teams and environments
๐งฉ Types of Terraform Modules 1๏ธโฃ Public Modules Available from Terraform Registry Maintained by providers or the community Cannot be modified internally
2๏ธโฃ Partner Modules Co-managed by HashiCorp and partners Verified and production-ready Still externally controlled.
3๏ธโฃ Custom Modules (Focus of Day 20) Created and maintained by you or your organization Full control over: Code Versioning Secโฆ
๐ง What Is a Terraform Module? A Terraform module is a reusable, self-contained package of Terraform code.
A module typically contains: main.tf โ resources variables.tf โ inputs outputs.tf โ exposed values Terraform treats every directory as a module.
Modules allow you to: Encapsulate complexity Enforce standards Reuse infrastructure patterns Scale cleanly across teams and environments
๐งฉ Types of Terraform Modules 1๏ธโฃ Public Modules Available from Terraform Registry Maintained by providers or the community Cannot be modified internally
2๏ธโฃ Partner Modules Co-managed by HashiCorp and partners Verified and production-ready Still externally controlled.
3๏ธโฃ Custom Modules (Focus of Day 20) Created and maintained by you or your organization Full control over: Code Versioning Security Updates ๐ Production systems rely heavily on custom modules.
๐ Root Module vs Custom Modules ๐น Root Module Entry point of the Terraform project Where terraform init and terraform apply are executed Orchestrates the entire infrastructure Sources and connects custom modules
๐น Custom Modules Stored as subdirectories inside the root module Each module has a single responsibility Do not directly communicate with each other The root module acts as the central coordinator.
๐ Typical Project Structure (Day 20 Style) terraform-project/ โโโ main.tf # Root module โโโ variables.tf โโโ outputs.tf โโโ modules/ โ โโโ vpc/ โ โ โโโ main.tf โ โ โโโ variables.tf โ โ โโโ outputs.tf โ โโโ eks/ โ โ โโโ main.tf โ โ โโโ variables.tf โ โ โโโ outputs.tf โ โโโ iam/ โ โโโ secrets/ Each module encapsulates a single infrastructure domain.
๐ How Modules Interact (Very Important) Custom modules never talk to each other directly.
All communication happens through the root module: Root module calls a custom module Passes input variables Custom module creates resources Custom module exposes outputs Root module consumes outputs Outputs are passed into other modules as inputs
This ensures: Loose coupling Clear dependency flow Maintainable architecture
๐ Example: VPC โ EKS Dependency Flow
- VPC module outputs vpc_id
- Root module captures vpc_id
- Root module passes vpc_id into EKS module
- EKS resources are created inside the correct VPC This pattern scales cleanly as infrastructure grows.
๐ฅ Variables & Outputs in Modular Design Variables Define what a module expects Passed from the root module Keep modules flexible
Outputs Define what a module exposes Used by the root module Enable inter-module coordination
Modules behave like functions: Inputs โ Processing โ Outputs
๐ Conclusion Day 20 transitions Terraform from learning mode to architecture mode.
This session makes it clear that:
- Terraform is not just about resources
- Terraform is about designing systems
- Custom modules are the backbone of production IaC
By mastering modular Terraform architecture, you unlock the ability to build large, maintainable, enterprise-grade cloud platforms.
This is how Terraform is used in the real world.