TE

Module Composition Pattern

Composable Terraform module architecture with reusable child modules and environment-specific root modules

Details

Language / Topic
terraformTerraform
Category
Architecture

Rules

balanced
- Structure repositories with `modules/` for reusable building blocks and `environments/` (or `live/`) for environment-specific root configurations that call those modules.
- Never put provider configuration inside reusable modules — define `required_providers` in `versions.tf` but configure providers only in root modules to preserve composability.
- Use module outputs to pass resource identifiers between modules rather than using `data` sources to look up resources that were just created in the same plan.
- Pin module source references to specific git tags or SHA hashes in production: `source = "git::https://github.com/org/modules.git//networking?ref=v1.4.0"`.