BlogIaC
Terragrunt: keeping 30 environments DRY
Stop copy-pasting backend and provider blocks across environments — generate them and keep inputs in one place.
At thirty environments, plain Terraform means thirty near-identical backend and provider blocks that drift the moment someone edits one. Terragrunt generates the boilerplate from a single root file and keeps only the per-environment inputs in each leaf — DRY without magic.
Define the backend once
root terragrunt.hcl
remote_state {backend = "s3"generate = { path = "backend.tf", if_exists = "overwrite" }config = {bucket = "acme-tfstate"key = "${path_relative_to_include()}/terraform.tfstate"region = "eu-west-1"encrypt = true}}
Each environment is just inputs
live/prod/app/terragrunt.hcl
include "root" { path = find_in_parent_folders() }terraform { source = "git::[email protected]:acme/modules.git//app?ref=v2.1" }inputs = {instance_count = 6environment = "prod"}
One backend definition, many states
The generated key uses the folder path, so every environment gets an isolated state file automatically — no copy-paste, no collisions.
Operate the whole tree
terragrunt run-all planlive/dev/app no changeslive/staging/app + 1 to addlive/prod/app no changes