Comprehensive toolkit for generating best practice Terragrunt configurations (HCL files) following current standards and conventions. Use this skill when creating new Terragrunt resources (root configs, child modules, stacks, environment setups), or building multi-environment Terragrunt projects.
Generate production-ready Terragrunt configurations following current best practices, naming conventions, and security standards. All generated configurations are automatically validated.
terragrunt stack generate # Generate unit configurationsterragrunt stack run plan # Plan all unitsterragrunt stack run apply # Apply all unitsterragrunt stack output # Get aggregated outputsterragrunt stack clean # Clean generated directories
Production Recommendation: For critical production resources, add exclude blocks to prevent accidental destruction:
hcl
# Protect production databases from accidental destroyexclude{if=trueactions=["destroy"]exclude_dependencies=false}# Also use prevent_destroy for critical resourcesprevent_destroy=true
Re-validate (repeat until ALL errors are resolved)
If validation succeeds: Present configurations with usage instructions
Skip validation only for: Partial snippets, documentation examples, or explicit user request
Presentation Requirements
MANDATORY: After successful validation, you MUST present ALL of the following sections. Incomplete presentation is not acceptable. Copy and fill in the templates below.
1. Directory Structure Summary (MANDATORY)
bash
# Show the generated structuretree <infrastructure-directory>
2. Files Generated (MANDATORY)
Output this table with all generated files:
markdown
| File | Purpose ||------|---------|| root.hcl | Shared configuration for all child modules (state backend, provider) || dev/env.hcl | Development environment variables || prod/env.hcl | Production environment variables || dev/vpc/terragrunt.hcl | VPC module for development || ... | ... |
3. Usage Instructions (MANDATORY)
You MUST include this section. Copy the template below and fill in the actual values:
markdown
## Usage Instructions### PrerequisitesBefore running Terragrunt commands, ensure:
1. AWS credentials are configured (`aws configure` or environment variables)
2. S3 bucket `<BUCKET_NAME>` exists for state storage
3. DynamoDB table `<TABLE_NAME>` exists for state locking
### Commands# Navigate to infrastructure directorycd <INFRASTRUCTURE_DIR># Initialize all modulesterragrunt run --all init
# Preview changes for a specific environmentcd <ENV>/vpc && terragrunt plan
# Preview all changesterragrunt run --all plan
# Apply changes (requires approval)terragrunt run --all apply
# Destroy (use with extreme caution)terragrunt run --all destroy
4. Environment-Specific Notes (MANDATORY)
You MUST include this section. Copy the template below and fill in the actual values:
markdown
## Environment Notes### Required Environment Variables| Variable | Description | Example ||----------|-------------|---------|| AWS_PROFILE | AWS CLI profile to use |`my-profile`|| AWS_REGION | AWS region (or set in provider) |`us-east-1`|### Prerequisites- [ ] S3 bucket `<BUCKET_NAME>` must exist before first run
- [ ] DynamoDB table `<TABLE_NAME>` must exist for state locking
- [ ] IAM permissions for Terraform state management
### Production-Specific Protections| Module | Protection | Description ||--------|------------|-------------|| prod/rds |`prevent_destroy = true`| Prevents accidental database deletion || prod/rds |`exclude { actions = ["destroy"] }`| Blocks destroy commands |
5. Next Steps (Optional)
Suggest what the user might want to do next (add more modules, customize configurations, etc.)
Error: Attempt to get attribute from null value
on ./root.hcl line X:
This value is null, so it does not have any attributes.
Cause: Root.hcl is trying to read
env.hcl
via
find_in_parent_folders("env.hcl")
, but env.hcl doesn't exist at the root level.
Solution: Make root.hcl environment-agnostic:
hcl
# DON'T do this in root.hcl for multi-environment setups:locals{env_vars= read_terragrunt_config(find_in_parent_folders("env.hcl")) # FAILS}# DO use static values or get_env():generate "provider"{path="provider.tf"if_exists="overwrite_terragrunt"contents=<<EOF
provider "aws" {
region = "us-east-1" # Static value, or use get_env("AWS_REGION", "us-east-1")
}
EOF}
Provider Conflict with Registry Modules
When using Terraform Registry modules (e.g.,
tfr:///terraform-aws-modules/vpc/aws
), they may define their own
required_providers
block. This can conflict with provider configuration generated by
root.hcl
.
Symptoms:
Error: Duplicate required providers configuration
Solutions:
Remove conflicting generate block - If using registry modules that manage their own providers, avoid generating duplicate
required_providers
:
hcl
# In root.hcl - only generate provider config, not required_providersgenerate "provider"{path="provider.tf"if_exists="overwrite_terragrunt"contents=<<EOF
provider "aws" {
region = "us-east-1"
}
EOF}
Use if_exists = "skip" - Skip generation if file already exists: