terragrunt
Terragruntのエキスパートとして、設定ファイルの重複を避け、リモートstateを管理し、複数環境への大規模なインフラ構築を効率化するSkill。
📜 元の英語説明(参考)
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.
🇯🇵 日本人クリエイター向け解説
Terragruntのエキスパートとして、設定ファイルの重複を避け、リモートstateを管理し、複数環境への大規模なインフラ構築を効率化するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o terragrunt.zip https://jpskill.com/download/15469.zip && unzip -o terragrunt.zip && rm terragrunt.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15469.zip -OutFile "$d\terragrunt.zip"; Expand-Archive "$d\terragrunt.zip" -DestinationPath $d -Force; ri "$d\terragrunt.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
terragrunt.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
terragruntフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Terragrunt — DRY な Terraform/OpenTofu ラッパー
あなたは Terragrunt のエキスパートです。Terragrunt は Terraform と OpenTofu のための薄いラッパーであり、設定を DRY に保ち、リモートステートを管理し、マルチモジュールデプロイメントを調整するための追加ツールを提供します。あなたはプラットフォームチームが Terragrunt の階層的な設定、依存関係管理、および before/after フックを使用して、複数の環境と AWS アカウントにわたる大規模なインフラストラクチャを管理するのを支援します。
主要な機能
DRY な設定
# infrastructure/terragrunt.hcl — ルート設定(すべての子に継承される)
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
}
## ディレクトリ構造
infrastructure/
├── terragrunt.hcl # ルート設定(共有設定)
├── modules/ # 再利用可能な Terraform モジュール
│ ├── 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"
}
コマンド
# 単一のモジュールで実行
cd infrastructure/production/us-east-1/api
terragrunt plan
terragrunt apply
# すべてのモジュールで実行(依存関係を考慮)
cd infrastructure/production/us-east-1
terragrunt run-all plan
terragrunt run-all apply
# 変更されたモジュールのみを実行
terragrunt run-all apply --terragrunt-include-dir api --terragrunt-include-dir database
# 依存関係のグラフ化
terragrunt graph-dependencies | dot -Tpng > deps.png
インストール
brew install terragrunt
# または https://terragrunt.gruntwork.io/ からダウンロード
# Terraform と OpenTofu の両方で動作します
ベストプラクティス
- 階層的な設定 —
find_in_parent_folders()を使用して設定を継承し、環境ごとに変更されるものだけをオーバーライドします。 - 依存関係 —
dependencyブロックを宣言します。Terragrunt は正しい順序で適用し、出力を入力として渡します。 - モジュールごとのリモートステート — 一意のステートキーには
path_relative_to_include()を使用します。モジュール間でステートを共有しないでください。 - オーケストレーションのための run-all —
terragrunt run-all applyは、依存関係の順序を考慮して環境全体をデプロイします。 - モジュールとライブ設定の分離 — 再利用可能なモジュールは
modules/に、環境設定はsourceを介してそれらを参照します。 - アカウント/リージョンの階層 — フォルダをアカウント → リージョン → 環境 → サービスの順に構成します。各レベルには独自の
.hclがあります。 - Before/after フック — 適用前/適用後に、検証、リンティング (
tflint)、または通知にフックを使用します。 - OpenTofu での動作 — Terraform の代わりに OpenTofu を使用するには、
TERRAGRUNT_TFPATH=tofuを設定します。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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