Terragrunt Explained: When You Actually Need It
Terragrunt keeps large Terraform setups DRY and orchestrated, but small teams often pay its learning curve for little return.
Key takeaways
- Terragrunt is a thin wrapper around Terraform and OpenTofu that generates repeated backend and provider config and runs many units in dependency order with terragrunt run --all.
- It pays off with many environments, many state files and a platform team.
- Below about ten state files, plain modules and a script are simpler.
On this page
Terragrunt is a wrapper around Terraform and OpenTofu that removes repeated backend and provider blocks and applies many state files in dependency order with terragrunt run --all apply. You need it when you run many environments across dozens of components with a team that owns the tooling. With one or two environments and under ten state files, skip it.
Verified against
Terragrunt 1.2.1 (released October 23, 2026), OpenTofu 1.10+ for S3 native locking, against the docs.terragrunt.com CLI, HCL blocks, functions and root-file migration pages. Checked October 2026.
Some teams swear Terragrunt saved them from copy-paste hell. Others rip it out after a year. Both are usually right, because it earns its keep in specific conditions and becomes dead weight outside them.
What Terragrunt actually is
Terragrunt does not replace Terraform. It calls the same terraform or tofu binary, produces the same plan and manages the same state. What it adds is a layer for the boilerplate Terraform makes you repeat: backend config, provider blocks, input wiring, and running commands across many root modules (Terragrunt calls each one a unit).
If you have never hit that boilerplate as a real problem, this sounds like a solution looking for one. That is the honest tension: it only makes sense once repetition genuinely hurts.
The problems it solves
DRY backend config. Terraform backend blocks cannot use variables. Try it and terraform init stops with Error: Variables not allowed and "Variables may not be used here." So teams hardcode the same bucket and region in dozens of places, changing only the key. Terragrunt generates the backend from one definition and computes the key per unit.
DRY provider config. Same story for provider blocks, assume-role settings and default tags. Terragrunt writes a provider.tf into each unit so you define it once.
Many environments. Dev, staging and prod belong in separate state files for blast-radius reasons, and the input differences between them are small. Terragrunt keeps module code in one place and feeds each environment its own inputs.
Dependencies between units. The VPC must exist before the database. dependency blocks pass one unit's outputs into another's inputs and enforce apply order, and terragrunt run --all apply walks the whole graph.
A working layout you can copy
Split versioned module code from the live configuration that instantiates it:
infra/
├── modules/ # reusable Terraform/OpenTofu modules
│ ├── vpc/
│ └── rds/
└── live/
├── root.hcl # shared: remote state + provider generation
├── dev/us-east-1/
│ ├── vpc/terragrunt.hcl
│ └── database/terragrunt.hcl
└── prod/us-east-1/
├── vpc/terragrunt.hcl
└── database/terragrunt.hcl
The root file holds everything every unit shares. Note the name: the docs now recommend root.hcl rather than a root terragrunt.hcl, which is deprecated and emits warnings.
# live/root.hcl
remote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
bucket = "acme-tofu-state"
key = "${path_relative_to_include()}/tofu.tfstate"
region = "us-east-1"
encrypt = true
use_lockfile = true # S3 native locking, needs OpenTofu 1.10+
}
}
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "aws" {
region = "us-east-1"
default_tags { tags = { managed_by = "terragrunt" } }
}
EOF
}
Each leaf is a few lines: include the root, point at a module version, supply inputs.
# live/prod/us-east-1/database/terragrunt.hcl
include "root" {
path = find_in_parent_folders("root.hcl")
}
terraform {
source = "git::git@github.com:acme/modules.git//rds?ref=v1.4.0"
}
dependency "vpc" {
config_path = "../vpc"
mock_outputs_allowed_terraform_commands = ["validate", "plan"]
mock_outputs = {
private_subnet_ids = ["subnet-mock"]
}
}
inputs = {
instance_class = "db.r6g.large"
subnet_ids = dependency.vpc.outputs.private_subnet_ids
environment = "prod"
}
Then run one unit, or a whole environment in dependency order:
$ cd infra/live/prod/us-east-1/database && terragrunt plan
$ cd ../../../ # back to infra/live
$ terragrunt run --all plan
$ terragrunt run --all --filter 'prod/**' -- apply
Older guides use terragrunt run-all apply; the current docs document run --all. Two behaviors to know: with apply or destroy, run --all adds -auto-approve for you (pass --no-auto-approve to stop that), and run --all destroy also destroys the dependencies of units under the working directory by default. A new environment is now a copied directory of small files, and module versions are pinned per unit, which pairs well with versioning modules through a shared registry.
When it breaks: errors and fixes
| Symptom | Cause | Fix |
|---|---|---|
Error: Variables not allowed in a backend block | Plain Terraform, no Terragrunt | Generate the backend from remote_state, or use -backend-config files |
plan fails on a unit whose dependency was never applied | dependency has no real outputs yet | Add mock_outputs and allow them for validate and plan only |
Unsupported attribute on dependency.x.outputs.y | The upstream unit has no such output, or it is mocked without it | Add the output upstream, or the key to mock_outputs |
Deprecation warning about a root terragrunt.hcl | Old root-file pattern | Rename to root.hcl and call find_in_parent_folders("root.hcl") |
Error acquiring the state lock | A crashed or concurrent run holds the lock | See fixing a Terraform state lock |
Mocked values reached a real apply | mock_outputs allowed for apply | Never list apply in mock_outputs_allowed_terraform_commands |
The docs also warn against setting TF_PLUGIN_CACHE_DIR with run --all; use Terragrunt's provider cache server instead.
The downsides
It is another layer. You debug across two tools: is the fault in your module, in generated code, or in orchestration? Generated backend.tf and provider.tf are not in source, which surprises first-time readers.
Learning curve. find_in_parent_folders, read_terragrunt_config, includes and the dependency/mock_outputs dance are a second mental model on top of Terraform.
Native features narrow the gap. Partial backend config with -backend-config files, provider default_tags, and Terraform's own stacks and test tooling all weaken the "no other option" argument. Terragrunt still does more, but the case is narrower than it was in 2019.
Alternatives
Native workspaces: fine for a few near-identical environments off one config; awkward once environments diverge.
Terramate: an orchestration layer with change detection, worth a look if orchestration is your main pain rather than DRY config.
Plain modules plus a wrapper script: a good module library and a short Makefile cover a lot of teams. You lose dependency graphs and keep the stack simple.
For where these sit, see the best Infrastructure-as-Code tools, and if you're weighing engines, Terraform vs OpenTofu.
Where this breaks
Terragrunt assumes many small state files. If you keep one big state per environment, there's little to orchestrate. If your team runs everything through HCP Terraform or another platform that already handles workspaces, variables and run ordering, Terragrunt duplicates it. And run --all is a sharp tool in production: one command can apply or destroy many units, so CI should plan with --filter and apply the saved plans, not run a blanket apply.
Questions people ask
Is Terragrunt still needed with OpenTofu or modern Terraform?
Less than it used to be, but yes at scale. Backend blocks still cannot take variables, so repeated backend config remains, and neither tool orchestrates many root modules in dependency order on its own. Partial backend config files and provider default tags cover small setups. Terragrunt still earns its place when you manage dozens of state files across several environments.
What is the difference between run-all and run --all?
They do the same job: run a Terraform or OpenTofu command across every unit in the current directory tree, in dependency order. run-all is the older spelling found in most blog posts. The current Terragrunt docs document terragrunt run --all plan and terragrunt run --all apply, plus --filter to narrow which units run. Update scripts to the new form.
When should a team not use Terragrunt?
When you have one or two environments, fewer than about ten state files, and no platform team to own the tooling. In that setup, the extra layer, generated files and second mental model cost more attention than they save. Plain modules, partial backend config files and a short Makefile are easier for the next engineer to read.
The call we'd make
Reach for Terragrunt when you run many environments across many components with a platform team that owns the tooling. That is exactly what it was built for, and it will save you from near-duplicate backend blocks and manual apply ordering. Skip it with one or two environments, a modest number of state files and no dedicated owner; plain modules and a thin script stay easier to reason about. Start without it, and adopt it the day repetition and apply ordering stop being annoyances and start being incidents.
Sources
Cite this article
Kiril Urbonas (2026). Terragrunt Explained: When You Actually Need It. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/terragrunt-explained
[Terragrunt Explained: When You Actually Need It](https://www.devopsness.com/blog/terragrunt-explained) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.