Key Components
Example Directory Tree
How It Works
- Global Settings
The rootterragrunt.hclprovides defaults for all modules and environments:- Remote state backend configuration
- Shared providers
- Pre/post hooks for automation
Define secure and centralized remote state backends in your root file to maintain state consistency across teams.
-
Environment Overrides
Each environment directory (envs/dev,envs/prod) contains:account.hclfor environment-specific parameters (account IDs, AWS region, etc.)common-vars.hclto share variable values among all components
-
Component-Specific Configuration
Insideenvs/<environment>/<component>/terragrunt.hclyou:- Include both the root configuration and the environment’s
account.hcl - Reference the corresponding module from
modules/<component> - Override or supplement module inputs as needed
- Include both the root configuration and the environment’s
-
Shared Variables
Usecommon-vars.hclto avoid repetition:
Avoid duplicating variables across component configs. Centralize values in
common-vars.hcl to prevent drift.Benefits
- Modularity: Break infrastructure into reusable modules.
- Clarity: Isolate environment-specific settings from shared defaults.
- Scalability: Easily add new environments or components without refactoring existing code.