Skip to main content
A well-organized directory layout simplifies management of Terraform configurations with Terragrunt, promotes reuse, and makes environment-specific customizations straightforward.

Key Components

Example Directory Tree

How It Works

  1. Global Settings
    The root terragrunt.hcl provides 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.
  1. Environment Overrides
    Each environment directory (envs/dev, envs/prod) contains:
    • account.hcl for environment-specific parameters (account IDs, AWS region, etc.)
    • common-vars.hcl to share variable values among all components
  2. Component-Specific Configuration
    Inside envs/<environment>/<component>/terragrunt.hcl you:
    • 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
  3. Shared Variables
    Use common-vars.hcl to 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.

Watch Video