agentleFS
eclosion-labseclosion-labs/terraform-cursor-plugin/skills/terraform-terragrunt/SKILL.md

terraform-terragrunt

Skill0 starsChanged 7 months agoMITView on GitHub

Terragrunt workflows for DRY Terraform: terragrunt.hcl units, generate blocks for provider/backend, dependency wiring with mock outputs, remote_state coordination, run-all batching, include chains, versioning considerations, and guidance on when the added complexity pays off versus plain Terraform modules. Use for multi-environment fleet management - not as default for tiny stacks.

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. About 0 are common, 5 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Use generate for boilerplate backend.tf / provider.tf files to avoid copy/paste across env folders - keep generated files .gitignored when …

    line 66
  2. Very specific:

    Provider version conflicts: when generated required_providers mismatches module - test init.

    line 136
  3. Very specific:

    Keep complex transforms in Terraform modules, not in inputs = { ...

    line 157
  4. Very specific:

    Avoid embedding secrets directly - use env vars / SOPS loaders.

    line 162
  5. Distinctive:

    Document exit path - some teams graduate to pure Terraform with reusable modules once fleet complexity drops.

    line 172
  6. Distinctive:

    Use it when repetition pain clearly exceeds wrapper overhead.

    line 178
  7. Very specific:

    Use manual gates between plan-all and apply-all stages - full automation without human review is rare for prod.

    line 215
  8. Very specific:

    If dependency.outputs empty, ensure dependency stack applied - Terragrunt doesn’t auto apply unless configured - see …

    line 220
  9. Distinctive:

    Test new Terragrunt versions against oldest supported Terraform in your estate - compat boundaries shift.

    line 239
  10. Very specific:

    Use aws ssm get-parameter in before_hook sparingly - failures stall plans.

    line 249
  11. Distinctive:

    After Terragrunt incidents, ask: “Would pure Terraform have been clearer?” Answer honestly quarterly.

    line 258
  12. Very specific:

    Treat each Terragrunt directory as a unit with contract tests in CI - terragrunt render-json can snapshot expected inputs for diffs during …

    line 267
  13. Very specific:

    When run-all spans accounts, ensure session naming identifies pipeline job IDs in CloudTrail - Terragrunt doesn’t add magic.

    line 272
  14. Very specific:

    If run-all apply fails halfway, rerun only failed units after fixing root cause - document command line snippets in runbook to avoid …

    line 277
  15. Very specific:

    Follow Terragrunt release notes for Terraform compatibility claims - pin pair (TG x.y, TF a.b) in internal standards doc.

    line 297
  16. Very specific:

    Use terragrunt graph-dependencies (if available in your version) and render to PNG in docs during major topology changes - picture …

    line 302
  17. Distinctive:

    Keep examples version-controlled without plaintext - pair with age recipients file in repo doc.

    line 321
  18. Very specific:

    When debugging, grab terragrunt dag/graph outputs plus underlying terraform plan logs - wrappers obscure root causes if you only keep …

    line 387

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Terragrunt: DRY orchestration around Terraform

Scope

Terragrunt is a thin wrapper that keeps Terraform code DRY across many environments by generating .tf fragments, orchestrating remote state, and coordinating run-all applies. It is not a replacement for well-factored modules.

terragrunt.hcl anatomy (typical)

include "root" {
  path = find_in_parent_folders("root.hcl")
}

terraform {
  source = "github.com/myorg/terraform-modules.git//app?ref=v3.2.0"
}

inputs = {
  env        = "prod"
  vpc_id     = dependency.network.outputs.vpc_id
  stream_arn = dependency.ingest.outputs.stream_arn
}

dependency "network" {
  config_path = "../network"

  mock_outputs = {
    vpc_id = "vpc-mock"
  }
  mock_outputs_allowed_terraform_commands = ["validate", "plan"]
}

dependency "ingest" {
  config_path = "../ingest"

  mock_outputs = {
    stream_arn = "arn:aws:kinesis:us-east-1:111111111111:stream/mock"
  }
  mock_outputs_allowed_terraform_commands = ["validate", "plan"]
}

generate "provider" {
  path      = "provider.tf"
  if_exists = "overwrite_terragrunt"
  contents  = <<EOF
provider "aws" {
  region = "us-east-1"
}
EOF
}

generate blocks

Use generate for boilerplate backend.tf / provider.tf files to avoid copy/paste across env folders - keep generated files .gitignored when policy demands (many teams commit them for transparency - pick one approach and document).

remote_state block

Terragrunt can configure remote_state once in root.hcl, injecting backend settings per unit - ensures uniform bucket/key naming (${path_relative_to_include()} patterns).

run-all

terragrunt run-all plan --terragrunt-non-interactive
terragrunt run-all apply --terragrunt-non-interactive

Understand parallelism and graph ordering - dependency links define hints; failures mid-run require manual triage across stacks.

When Terragrunt is worth it

Yes when:

  • Dozens of similar env folders need shared backend/provider snippets.
  • You want enforced ordering hints between stacks (dependency).
  • Monorepo with clear directory per env.

No when:

  • Single root module with a few workspaces - native Terraform workspaces or separate stacks suffice.
  • Team lacks bandwidth to debug wrapper issues - pure Terraform reduces moving parts.

Version coupling

Pin Terragrunt versions in CI like Terraform - upgrades can change parsing behavior.

include chains

find_in_parent_folders enables hierarchical configuration - great power, great confusion if depth changes; add comments explaining folder layout in README.

Mock outputs pitfalls

Mock outputs allow validate without live apply of dependencies - misconfigured mocks hide missing outputs until integration - periodically run full ordered apply in staging.

generate + fmt

Generated files might not pass terraform fmt if templates sloppy - lint generation templates.

Hooks

Terragrunt before_hook / after_hook can run tflint, checkov - keep hooks fast to preserve dev UX.

CI integration

Wrap terragrunt run-all plan with IAM role assuming per account; matrix by account folder.

State key conventions

Encode account/env in state keys consistently - Terragrunt’s relative path pattern helps until teams move folders - mind refactors.

When not to use this skill

Terraform-only module authoring → terraform-modules.

Common errors

  • Cyclic dependency between terragrunt units - break by introducing third bootstrap unit.
  • Provider version conflicts when generated required_providers mismatches module - test init.

Interop with Terraform Cloud

Remote backend integration differs - validate whether Terragrunt generation fights Terraform Cloud workspaces - some teams skip Terragrunt in TFC-only flows.

Local development ergonomia

terragrunt hclfmt formats HCL consistently - pre-commit friendly.

Testing strategy

Smoke test single unit before run-all in CI to isolate failures faster.

Documentation

Draw folder tree diagrams in repo root - new hires struggle without visual maps.

Anti-pattern: business logic in terragrunt

Keep complex transforms in Terraform modules, not in inputs = { ... massive ternary ... } - Terragrunt should orchestrate, not implement algorithms.

Secrets in terragrunt.hcl

Avoid embedding secrets directly - use env vars / SOPS loaders; Terragrunt can read_terragrunt_config across includes - watch for accidental secret commit in generated files.

Performance

run-all may download modules repeatedly - enable download directories caching options (per Terragrunt version docs) in CI.

Migration off terragrunt

Document exit path - some teams graduate to pure Terraform with reusable modules once fleet complexity drops; keep migration notes to avoid lock-in fear.

Closing

Terragrunt rewards discipline - without folder conventions and CI guardrails, it amplifies chaos. Use it when repetition pain clearly exceeds wrapper overhead.

Advanced: read_terragrunt_config

Compose configs dynamically - powerful for multi-region loops - beware readability; complex Terragrunt can be harder to debug than HCL in .tf modules.

Windows paths

find_in_parent_folders behaves differently under Git bash vs PowerShell - standardize dev environment or document gotchas.

include path limits

Very deep repos may hit path length limits on Windows - another reason CI uses Linux.

run-all graph exports

Some teams export Terragrunt dependency graphs into documentation during releases - helps auditors see blast radius ordering.

Terragrunt vs workspaces

Workspaces split state within one config; Terragrunt typically splits directories - choose based on desired PR granularity - monolithic workspace PRs scare reviewers.

State encryption alignment

Even with Terragrunt, backend encryption remains paramount - remote_state config must still set KMS keys.

Provider generation caution

Generating multiple provider aliases requires careful template testing - one typo duplicates providers block wide.

run-all apply approvals

Use manual gates between plan-all and apply-all stages - full automation without human review is rare for prod.

Troubleshooting pointers

If dependency.outputs empty, ensure dependency stack applied - Terragrunt doesn’t auto apply unless configured - see terraform-troubleshooting for underlying Terraform errors masked by wrapper.

Community plugins

Third-party Terragrunt extensions exist - evaluate support burden before adopting - plain hooks often suffice.

Benchmark anecdote

Teams report faster developer onboarding with Terragrunt when folder patterns consistent - measure your own p50 terragrunt plan times quarterly.

Final mantra

Terragrunt should delete repetition, not add mystery - if new engineers need a two-hour lecture to run plan, simplify.

Upgrade testing matrix

Test new Terragrunt versions against oldest supported Terraform in your estate - compat boundaries shift.

Observability

Wrap run-all logs with timestamps and unit names - parallel logs interleave confusingly in naive CI captures.

Secrets injection pattern

Use aws ssm get-parameter in before_hook sparingly - failures stall plans; prefer CI to export env.

Coordination with monorepo scanners

Point Checkov/Trivy at generated .tf directories when committed - or scan only source modules if generated files excluded; align policy to avoid blind spots.

Retrospective prompts

After Terragrunt incidents, ask: “Would pure Terraform have been clearer?” Answer honestly quarterly.

Summary

Terragrunt is glue - valuable glue, but still glue - don’t let it become the place where unclear architecture hides.

Unit test analogy

Treat each Terragrunt directory as a unit with contract tests in CI - terragrunt render-json can snapshot expected inputs for diffs during refactors.

IAM role chaining

When run-all spans accounts, ensure session naming identifies pipeline job IDs in CloudTrail - Terragrunt doesn’t add magic; roles must still be least privilege.

Partial applies recovery

If run-all apply fails halfway, rerun only failed units after fixing root cause - document command line snippets in runbook to avoid accidental full reruns costing time.

Caching downloaded modules

Configure TERRAGRUNT_DOWNLOAD paths in CI to reuse module downloads - invalidate when lock files change - speed matters on large fleets.

CLI autocomplete

Ship shell autocomplete instructions for engineers - small quality-of-life reduces typos in long run-all invocations.

Disaster recovery

Back up Terragrunt include trees as zealously as Terraform modules - losing root.hcl hurts as much as losing backend.tf.

Roadmap awareness

Follow Terragrunt release notes for Terraform compatibility claims - pin pair (TG x.y, TF a.b) in internal standards doc.

Visualizing dependencies

Use terragrunt graph-dependencies (if available in your version) and render to PNG in docs during major topology changes - picture clarifies ordering arguments in PR reviews.

Pairing with Atlantis

Atlantis project definitions can call Terragrunt per directory - standardize comment commands (atlantis plan -p network) mapping cleanly to Terragrunt units - confusion here spawns mis-applies.

Avoiding god includes

root.hcl growing unbounded hints missing Terraform module abstraction - refactor repeated inputs constructs into modules instead of mega includes.

SOPS integration example sketch

read_terragrunt_config(find_in_parent_folders("encrypted.hcl"))

Keep examples version-controlled without plaintext - pair with age recipients file in repo doc.

Culture

Senior engineers should occasionally terragrunt run-all plan locally on laptops mirroring CI, catching parallelism issues early instead of only in pipelines.

Final checklist

  • Folder conventions documented?
  • Mock outputs tested?
  • CI pins Terragrunt version?
  • Backend generation reviewed for KMS?
  • Secrets not in HCL?

Closing line

Terragrunt’s payoff is scale: many similar stacks with shared bones - without scale, prefer simpler tools.

Multi-region duplication

Symlink or template terragrunt.hcl per region carefully - accidental symlink loops confuse Git on Windows; prefer explicit copies with shared root.hcl if symlinks painful.

Cost ownership

run-all encourages many stacks - ensure FinOps reviews folder sprawl; inactive stacks still cost money even if Terragrunt config elegant.

Audit exports

For regulated customers, export rendered Terragrunt JSON inputs per release tag - proves what values were seen during Terraform execution.

Developer laptop resource usage

Parallelism on laptops can peg CPU - teach TERRAGRUNT_PARALLELISM tuning for humane local dev experience.

Naming collision between units

Prefix Terragrunt-managed DynamoDB lock entries (if any) uniquely - some teams share locking infra across mono repo units; misconfiguration causes spooky cross-talk.

Editor support

VS Code Terragrunt extension maturity fluctuates - fallback to HCL syntax highlighting if specialized features buggy; don’t block adoption on IDE polish.

Layered environments (dev/stage/prod)

Promote modules by bumping terraform.source ref sequentially through env folders - git diff of bumps should be trivially reviewable.

Bootstrap ordering

First-time org setup requires S3+Dynamo stack applied before others - Terragrunt dependency cannot fabricate buckets that don’t exist - human bootstrap still real.

Long path names on CI

Shorten path_relative_to_include() segments if S3 object key length approaches limits - especially for deep monorepos.

Post-incident note

When debugging, grab terragrunt dag/graph outputs plus underlying terraform plan logs - wrappers obscure root causes if you only keep Terragrunt stdout.

Encouraging modular thinking

Terragrunt is not license to skip module semver hygiene - keep modules small; Terragrunt composes, not replaces, module quality.

Final reassurance

Used well, Terragrunt reduces copy/paste defects; used poorly, it hides them behind indirection - pick your team’s maturity level honestly.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.