Terragrunt DRY Configuration Prompt
Restructure a sprawling multi-account, multi-region Terraform repo into a DRY Terragrunt layout — root config, includes, dependency wiring, and run-all orchestration — without breaking existing state.
- Target user
- Platform engineers managing many Terraform stacks across accounts and regions
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a staff platform engineer who has cut thousands of lines of copy-pasted Terraform backend blocks down to a single root Terragrunt config across dozens of accounts.
I will provide:
- Current directory tree and how environments/accounts/regions are split today
- A representative `backend.tf`, `provider.tf`, and `terraform { }` block from two stacks
- Existing remote state layout (bucket/key/dynamodb naming)
- Pain points (drift between envs, duplicated provider config, slow apply ordering)
Your job:
1. **Target layout** — propose a `live/` (env instances) vs `modules/` (or `_envcommon/`) split. Show the full tree: `account/region/component/terragrunt.hcl`, a root `root.hcl`, and shared `_envcommon` units.
2. **DRY the backend** — write the root `remote_state` block that generates each stack's backend key from `path_relative_to_include()`. Show exactly one place where bucket/region/lock table are defined.
3. **Generated providers** — use a `generate "provider"` block so no stack hand-writes provider config. Cover assume-role per account and provider aliases for multi-region.
4. **Inputs hierarchy** — show how `include` + `read_terragrunt_config` merges account-level, region-level, and env-level inputs. Make precedence explicit.
5. **Dependencies** — wire `dependency` and `dependencies` blocks (e.g. network → cluster → app). Show `mock_outputs` for plan-time and how to avoid the apply-order footguns.
6. **run-all safety** — give the `terragrunt run-all plan/apply` invocation, `--terragrunt-parallelism` guidance, and why `run-all apply` across accounts in CI needs `--terragrunt-non-interactive` plus per-stack approval gates.
7. **Migration without recreation** — for each existing stack, map old state key → new generated key, the `terragrunt state` / S3 copy steps, and a dry-run verification (`plan` must show zero changes) before deleting old keys.
8. **OpenTofu note** — show the `terraform_binary` / `tofu` switch if they may migrate.
Output as: (a) annotated target tree, (b) root.hcl, (c) one example leaf terragrunt.hcl, (d) state-migration runbook with verification gates, (e) the top 5 mistakes teams make adopting Terragrunt.
Bias toward: one source of truth per concern, plan-shows-no-changes as the migration success metric, and explicit dependency ordering over implicit luck.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terragrunt to Native Stacks Migration Prompt
Evaluate and plan a migration from a Terragrunt DRY setup to native Terraform Stacks (or OpenTofu stacks) — mapping `terragrunt.hcl` patterns, dependencies, and generate blocks onto first-class language features.
-
Terraform Stacks Deferred Changes Planning Prompt
Plan and reason about deferred changes across Stack components so unknown-count expansions apply safely in dependency order
-
Terraform Cross-Account Resource Migration Prompt
Plan moving Terraform-managed resources between cloud accounts or subscriptions without destroy/recreate or data loss.
-
Terraform Stacks Deployments Design Prompt
Design a Terraform Stacks (HCP) configuration that splits components from deployments, so one set of modules fans out across regions, accounts, and environments with orchestrated dependency ordering.
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.