Terragrunt
Skill ComeOnOliver/skillshub/skills/TerminalSkills/skills/terragrunt
π§ The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.From the repository description
npx -y skills add ComeOnOliver/skillshub --skill terragruntAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
4.8 KB, ~1.2k tokens by cl100k_base, as published. Nobody here has run it
Terragrunt β DRY Terraform/OpenTofu Wrapper
You are an expert in Terragrunt, the thin wrapper for Terraform and OpenTofu that provides extra tools for keeping configurations DRY, managing remote state, and orchestrating multi-module deployments. You help platform teams manage large-scale infrastructure across multiple environments and AWS accounts using Terragrunt's hierarchical configuration, dependency management, and before/after hooks.
Core Capabilities
DRY Configuration
# infrastructure/terragrunt.hcl β Root config (inherited by all children)
remote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite"
}
config = {
bucket = "company-terraform-state"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "terraform-locks"
}
}
generate "provider" {
path = "provider.tf"
if_exists = "overwrite"
contents = <<EOF
provider "aws" {
region = "${local.region}"
default_tags {
tags = {
Environment = "${local.environment}"
ManagedBy = "terragrunt"
}
}
}
EOF
}
locals {
account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl"))
env_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
account_id = local.account_vars.locals.account_id
region = local.region_vars.locals.region
environment = local.env_vars.locals.environment
}
## Directory Structure
infrastructure/
βββ terragrunt.hcl # Root config (shared settings)
βββ modules/ # Reusable Terraform modules
β βββ vpc/
β βββ ecs-service/
β βββ rds/
βββ production/
β βββ account.hcl # account_id = "111111111111"
β βββ us-east-1/
β β βββ region.hcl # region = "us-east-1"
β β βββ env.hcl # environment = "production"
β β βββ vpc/
β β β βββ terragrunt.hcl
β β βββ api/
β β β βββ terragrunt.hcl
β β βββ database/
β β βββ terragrunt.hcl
βββ staging/
βββ account.hcl # account_id = "222222222222"
βββ us-east-1/
βββ region.hcl
βββ env.hcl # environment = "staging"
βββ vpc/
βββ api/
βββ database/
# infrastructure/production/us-east-1/api/terragrunt.hcl
include "root" {
path = find_in_parent_folders()
}
terraform {
source = "../../../modules/ecs-service"
}
dependency "vpc" {
config_path = "../vpc"
}
dependency "database" {
config_path = "../database"
}
inputs = {
service_name = "api"
vpc_id = dependency.vpc.outputs.vpc_id
subnet_ids = dependency.vpc.outputs.private_subnet_ids
database_url = dependency.database.outputs.connection_string
desired_count = 3 # Production: 3 instances
cpu = 512
memory = 1024
container_image = "company/api:latest"
}
Commands
# Run in a single module
cd infrastructure/production/us-east-1/api
terragrunt plan
terragrunt apply
# Run across ALL modules (respects dependencies)
cd infrastructure/production/us-east-1
terragrunt run-all plan
terragrunt run-all apply
# Run only modules that changed
terragrunt run-all apply --terragrunt-include-dir api --terragrunt-include-dir database
# Graph dependencies
terragrunt graph-dependencies | dot -Tpng > deps.png
Installation
brew install terragrunt
# Or download from https://terragrunt.gruntwork.io/
# Works with both Terraform and OpenTofu
Best Practices
- Hierarchical configs β Use
find_in_parent_folders()to inherit settings; override only what changes per environment - Dependencies β Declare
dependencyblocks; Terragrunt applies in the right order and passes outputs as inputs - Remote state per module β Use
path_relative_to_include()for unique state keys; never share state between modules - run-all for orchestration β
terragrunt run-all applydeploys entire environments respecting dependency order - Separate modules from live config β Reusable modules in
modules/; environment configs reference them viasource - Account/region hierarchy β Structure folders by account β region β environment β service; each level has its
.hcl - Before/after hooks β Use hooks for validation, linting (
tflint), or notifications before/after apply - Works with OpenTofu β Set
TERRAGRUNT_TFPATH=tofuto use OpenTofu instead of Terraform
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.