Terraform Advanced — What Is Terragrunt

less than 1 minute read

Terragrunt is a thin wrapper around Terraform that solves code duplication, backend configuration, and dependency ordering.


The Problem Terragrunt Solves

Without Terragrunt:

environments/
├── dev/vpc/main.tf         # Copy of module call
├── dev/eks/main.tf         # Copy of module call
├── staging/vpc/main.tf     # Same copy, different vars
├── staging/eks/main.tf     # Same copy, different vars
├── prod/vpc/main.tf        # Same copy, different vars
└── prod/eks/main.tf        # Same copy, different vars

6 copies of essentially the same code!

With Terragrunt:

environments/
├── terragrunt.hcl          # Root: backend config, provider config
├── dev/
│   ├── env.hcl             # env = "dev"
│   ├── vpc/terragrunt.hcl  # Just inputs + module source
│   └── eks/terragrunt.hcl
├── staging/
│   ├── env.hcl
│   ├── vpc/terragrunt.hcl
│   └── eks/terragrunt.hcl
└── prod/
    ├── env.hcl
    ├── vpc/terragrunt.hcl
    └── eks/terragrunt.hcl

Each terragrunt.hcl is ~10 lines instead of 50+

Install Terragrunt

# macOS
$ brew install terragrunt

# Verify
$ terragrunt --version
terragrunt version v0.67.0

What’s Next?

Understand the terragrunt.hcl file structure.

← Terragrunt terragrunt.hcl Structure →

Updated: