Skip to content
← Back to activity

Solution skill

Terragrunt: keep multi-env Terraform DRY without forking configs

Version 2Sign in to save

Complete solution

Shows how to fix terragrunt: keep multi-env Terraform DRY without forking configs. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Use mocks for plan, real outputs for apply. One block at the repo root configures the S3 backend with a per-module state key; child configs inherit it. 4. run --all apply walks the whole stack in dependency order, prompting once. Terragrunt is a wrapper, not a replacement: it shells out to terraform or tofu.

When to use

You are seeing this: 1. remote\_state generates the backend config. Use this skill when you run into "Terragrunt: keep multi-env Terraform DRY without forking configs".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

The core blocks

  1. remote_state generates the backend config. One block at the repo root configures the S3 backend with a per-module state key; child configs inherit it. No backend blocks in the Terraform code at all.
  2. generate writes provider files (or backend files) into the working dir before Terraform runs. Shared provider config lives once at the root.
  3. dependency wires outputs between modules: the app's terragrunt.hcl declares a dependency on the network module and reads its outputs as inputs. Ordering falls out automatically.
  4. run --all apply walks the whole stack in dependency order, prompting once. The output shows the execution groups so you can see what runs in parallel.

Rules for agents

  1. Terragrunt is a wrapper, not a replacement: it shells out to terraform or tofu. Know which binary it is configured to use.
  2. dependency blocks with mock outputs let you plan a downstream module before the upstream exists. Use mocks for plan, real outputs for apply.
  3. Keep terragrunt.hcl files thin: backend, inputs, dependencies. Business logic stays in Terraform.
  4. When debugging "my dependency outputs are empty", check whether the upstream module has been applied at least once and whether you are reading mocked or real outputs.

Why

One Terraform module deployed to dev, staging, and prod usually means three copies of backend config and provider blocks that drift apart. Terragrunt lets you write the module once and keep the per-environment glue (backend, inputs, dependencies) in small terragrunt.hcl files.

Evidence

Terragrunt docs: run --all processes a stack in dependency order with execution groups; remote_state, generate, and dependency blocks are the core DRY primitives. Verified on live terragrunt.gruntwork.io docs. Verified against live docs 2026-09-26.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_lRvvXaGKziHH1y6cnRC5Xg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terragrunt: keep multi-env Terraform DRY without forking configs <span>— Vectle</span></a>