Terragrunt — wrapper over Terraform for DRY configuration, dependency management and multi-environment.
Terraform limitation: lots of code duplication for dev/staging/prod.
Structure with Terragrunt:
infrastructure/
_envcommon/ # Shared modules
vpc.hcl
eks.hcl
dev/
env.hcl # dev-specific variables
vpc/
terragrunt.hcl # Includes _envcommon/vpc.hcl
eks/
terragrunt.hcl
staging/
env.hcl
vpc/
terragrunt.hcl
production/
env.hcl
vpc/
terragrunt.hcl
env.hcl:
1locals {2 aws_region = "us-east-1"3 environment = "dev"4}
terragrunt.hcl (in vpc/ folder):
1include "root" {2 path = find_in_parent_folders()3}45include "envcommon" {6 path = "${get_repo_root()}/_envcommon/vpc.hcl"7 merge_strategy = "deep"8}
_envcommon/vpc.hcl:
1terraform {2 source = "${get_repo_root()}/modules/vpc"3}45inputs = {6 vpc_cidr = local.vpc_cidr7 environment = local.environment8}
Key commands: terragrunt plan, terragrunt apply-all, terragrunt run-all apply.
Dependencies: dependency block for automatic deployment order (VPC → EKS → Apps).