Build Phase
The Build phase organizes and structures IaC into a repository model that enforces consistency.
Core Concepts
- Repository Structure: Organized into
modules/,solutions/, anddeployments/directories - Solutions enforce consistency across services by explicitly defining constraints
Example Repository Structure
your-idlc-repo/
├── modules/
│ ├── s3/
│ │ └── bucket/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ ├── outputs.tf
│ │ └── versions.tf
│ ├── rds/
│ │ ├── postgres-database/
│ │ ├── parameter-group/
│ │ └── alarms/
│ └── eks/
│ ├── cluster/
│ ├── karpenter/
│ └── irsa/
├── solutions/
│ ├── my-app/
│ │ ├── main.tf # Composes modules
│ │ ├── variables.tf # Only what varies
│ │ └── outputs.tf
│ └── my-database/
│ ├── main.tf
│ └── variables.tf
└── deployments/
├── region-1/
│ ├── stage/
│ │ └── my-app/
│ │ └── terragrunt.hcl
│ └── production/
│ ├── root.hcl
│ └── my-app/
│ └── terragrunt.hcl
└── region-2/
└── production/
└── my-app/
└── terragrunt.hcl
Module File Convention
Every module should contain:
| File | Purpose |
|---|---|
main.tf |
Resource definitions |
variables.tf |
Input variables with validation |
outputs.tf |
Output values |
versions.tf |
Provider and Terraform version constraints |
README.md |
Auto-generated by terraform-docs |
CHANGELOG.md |
Auto-generated by release-please |
Documentation
Documentation is generated from code comments using terraform-docs and included in the module’s README.md. This ensures documentation is always up-to-date with the code.
But is highly recommended to add a custom block into README.md with usage examples, architectural decisions, and any non-obvious details that code comments can’t capture.
Our custom documentation block (not generated by terraform-docs)
<!-- BEGIN_TF_DOCS -->
Auto gererated documentation from terraform-docs will be injected here
<!-- END_TF_DOCS -->
Best Practices
- Use clear, consistent naming for directories and modules
- Enforce non-configurable defaults in solutions (security, policies)
- Keep modules focused on a single responsibility
- Use
versions.tfto pin provider versions
Build is about structure and enforcement. A well-organized repository makes the Code and Deploy phases significantly easier.