The Complete Production SOP: How to Deploy and Run Terragrunt DRY Multi-Account Infrastructure Orchestration in Autonomous AI Agents
Step-by-step SOP to install and run Terragrunt DRY Multi-Account Infrastructure Orchestration in Codex, Claude Code, and Cursor. Verified prompts & fixes.
Technical Overview & Architectural Context
Autonomous coding agents frequently stumble when generating Terragrunt architectures because standard Large Language Models conflate vanilla Terraform root modules with Terragrunt dynamic include wrappers. Left unconstrained, models duplicate remote backend configurations across leaf directories, hardcode cross-stack state references using brittle terraform_remote_state data sources, or hallucinate circular dependency paths in leaf terragrunt.hcl files. This breaks AWS multi-account governance and produces high-blast-radius execution failures during infrastructure rollouts. The 'terragrunt-dry-infrastructure' skill enforces strict, deterministic SOP boundaries. It guarantees that agents construct centralized root terragrunt.hcl files using generate blocks for providers and remote state, dynamically link child stacks via find_in_parent_folders(), and resolve cross-module references strictly using mock-safe dependency blocks. Furthermore, it enforces non-interactive dry-run workflows via terragrunt run-all plan before applying changes across multi-account topologies.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into your agent runtime.
Autonomous runtimes such as Codex and Claude Code scan project root `.agents/skills` or `.claude/skills` directories on boot. By downloading and pinning the validated SKILL.md file into your repository tree, you provide the agent with zero-shot domain constraints governing Terragrunt block syntax, dependency resolution, and execution flags.
mkdir -p .agents/skills/terragrunt-dry-infrastructure && curl -fsSL https://askills.dev/api/skills/terragrunt-dry-infrastructure/raw -o .agents/skills/terragrunt-dry-infrastructure/SKILL.md---
name: "terragrunt-dry-infrastructure"
description: "Keep Terraform code DRY across multiple AWS accounts, regions, and environments with Terragrunt."
metadata:
author: "Gruntwork"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "keep terraform dry terragrunt"
- "terragrunt dependency block"
- "run terragrunt run-all apply"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Hot-reload the agent workspace configuration by executing `/skills reload` in Claude Code or restarting the Cursor Composer index window to ingest frontmatter triggers immediately.
Ensure `shell_exec: false` remains respected unless elevated manually; the agent should author `.hcl` manifests without executing destructive cloud-side commands autonomously.
Establish Root Layout & Environment Variables
Configure workspace environment markers and root terragrunt.hcl generation logic without secret leakage.
To maintain a 100% DRY architecture, child directories must not contain duplicated S3 backend configurations or AWS provider definitions. Instruct the agent to establish an environment structure (`accounts/dev/us-east-1/vpc`) and define root-level `terragrunt.hcl` generation blocks using environment variables for the AWS partition and target accounts.
mkdir -p live/dev/us-east-1/vpc live/dev/us-east-1/eks && touch live/terragrunt.hclremote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
bucket = "corp-tf-state-${get_aws_account_id()}"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "corp-tf-locks"
}
}
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "aws" {
region = "${read_terragrunt_config(find_in_parent_folders("region.hcl")).locals.aws_region}"
}
EOF
}Never store AWS secrets directly in `terragrunt.hcl` files. Inject IAM assume-role definitions via `read_terragrunt_config()` pulling from local uncommitted `.env.local` or environment files.
Prevent the agent from executing recursive `find_in_parent_folders()` without checking that boundary root `.hcl` files actually exist in parent directories, otherwise Terragrunt parsing will halt.
Intent Matching & Trigger Invocation
Activate deterministic multi-stack orchestration using calibrated natural language triggers.
Instruct your agent to write leaf configurations by triggering the exact frontmatter matches. The agent will invoke its dependency orchestration rulebook, wiring dependent stacks via `dependency` blocks with fallback mock outputs for safe planning.
include "root" {
path = find_in_parent_folders()
}
terraform {
source = "tfr:///terraform-aws-modules/eks/aws?version=19.15.3"
}
dependency "vpc" {
config_path = "../vpc"
mock_outputs = {
vpc_id = "vpc-00000000000000000"
private_subnets = ["subnet-00000000", "subnet-11111111"]
}
mock_outputs_allowed_terraform_commands = ["validate", "plan"]
}
inputs = {
cluster_name = "dev-cluster"
vpc_id = dependency.vpc.outputs.vpc_id
subnet_ids = dependency.vpc.outputs.private_subnets
}Always mandate `mock_outputs_allowed_terraform_commands` on dependency blocks so that `terragrunt run-all plan` succeeds even before underlying infrastructure is deployed.
Do not permit the agent to point `config_path` to absolute file paths; all dependency linkages must use relative workspace paths.
Verification, Linting & Output Quality Gate
Run local Terragrunt parsing, HCL formatting, and non-interactive static validation checks.
Before accepting changes from Codex or Claude Code, enforce a multi-tier linting step. The agent must verify that all manifests compile cleanly, HCL follows canonical formatting, and Terragrunt graph dependencies form an acyclic directed graph (DAG).
terragrunt hclfmt --terragrunt-check && terragrunt run-all validate --terragrunt-non-interactiveInstruct the agent to review `git diff --stat` to guarantee no accidental backend generation artifacts (`backend.tf`, `.terragrunt-cache/`) are scheduled for commit.
Add `.terragrunt-cache/` to `.gitignore` immediately; agents will frequently attempt to stage cache binaries if left unmonitored.
Real-World Scenario: Multi-Account AWS Networking and EKS Orchestration
“We need to keep terraform dry terragrunt for our 'staging' AWS account. Setup a clean Terragrunt layout with a root configuration, a VPC stack, and an EKS cluster stack that references the VPC outputs via a terragrunt dependency block. Validate with run-all plan.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent invoked find_in_parent_folders() from a directory positioned at or above the root terragrunt.hcl file, or executed commands from outside the repository root.
Specify the fallback file parameter or correct directory structure: include "root" { path = find_in_parent_folders("terragrunt.hcl") }Root Cause: The child module runs a plan or validate command relying on dependency outputs that have not yet been deployed to remote state.
Add mock outputs to the dependency declaration: dependency "vpc" { config_path = "../vpc"; mock_outputs = { vpc_id = "mock-vpc-id" }; mock_outputs_allowed_terraform_commands = ["validate", "plan"] }Frequently Asked Questions (Terragrunt DRY Multi-Account Infrastructure Orchestration SOP)
Q:Can I use Terragrunt DRY Multi-Account Infrastructure Orchestration across Codex, Claude Code, and Cursor simultaneously?
Yes. This skill is packaged according to the universal open SKILL.md specification. Its declarative instructions, regex triggers, and tool boundaries operate identically across OpenAI Codex, Anthropic Claude Code, Cursor Composer, and Windsurf Cascade.
Q:How does Terragrunt DRY Multi-Account Infrastructure Orchestration prevent context window overflow during long agent sessions?
The skill enforces modular directory design and strictly delegates state management to declarative Terragrunt inputs. Instead of requiring the agent to read massive 2,000-line monolithic Terraform files into context, the agent only reads concise 30-line `terragrunt.hcl` declarations.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100. It restricts agent capabilities to local workspace read and write permissions (`fs_write: workspace`), explicitly prohibiting arbitrary remote shell executions without human oversight.
Ready to equip your autonomous agent with Terragrunt DRY Multi-Account Infrastructure Orchestration?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.