본문으로 건너뛰기
cccskills
무료GitHub에 공개

terraform-module-library

Infrastructure as Codeベストプラクティスに従って、AWS、Azure、GCPインフラ用の再利用可能なTerraformモジュールを構築します。インフラモジュール作成、クラウドプロビジョニング標準化、再利用可能なIaCコンポーネント実装時に使用します。

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md6.2 KB
  • references/aws-modules.md1.9 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

English | 日本語

Terraformモジュールライブラリ

AWS、Azure、GCPインフラ用の本番環境対応Terraformモジュールパターン。

目的

複数のクラウドプロバイダーにまたがる一般的なクラウドインフラパターン用の再利用可能で、十分にテストされたTerraformモジュールを作成します。

使用タイミング

  • 再利用可能なインフラコンポーネントの構築
  • クラウドリソースプロビジョニングの標準化
  • Infrastructure as Codeベストプラクティスの実装
  • マルチクラウド互換モジュールの作成
  • 組織のTerraform標準の確立

モジュール構造

terraform-modules/
├── aws/
│   ├── vpc/
│   ├── eks/
│   ├── rds/
│   └── s3/
├── azure/
│   ├── vnet/
│   ├── aks/
│   └── storage/
└── gcp/
    ├── vpc/
    ├── gke/
    └── cloud-sql/

標準モジュールパターン

module-name/
├── main.tf          # メインリソース
├── variables.tf     # 入力変数
├── outputs.tf       # 出力値
├── versions.tf      # プロバイダーバージョン
├── README.md        # ドキュメント
├── examples/        # 使用例
│   └── complete/
│       ├── main.tf
│       └── variables.tf
└── tests/           # Terratestファイル
    └── module_test.go

AWS VPCモジュール例

main.tf:

resource "aws_vpc" "main" {
  cidr_block           = var.cidr_block
  enable_dns_hostnames = var.enable_dns_hostnames
  enable_dns_support   = var.enable_dns_support

  tags = merge(
    {
      Name = var.name
    },
    var.tags
  )
}

resource "aws_subnet" "private" {
  count             = length(var.private_subnet_cidrs)
  vpc_id            = aws_vpc.main.id
  cidr_block        = var.private_subnet_cidrs[count.index]
  availability_zone = var.availability_zones[count.index]

  tags = merge(
    {
      Name = "${var.name}-private-${count.index + 1}"
      Tier = "private"
    },
    var.tags
  )
}

resource "aws_internet_gateway" "main" {
  count  = var.create_internet_gateway ? 1 : 0
  vpc_id = aws_vpc.main.id

  tags = merge(
    {
      Name = "${var.name}-igw"
    },
    var.tags
  )
}

variables.tf:

variable "name" {
  description = "VPCの名前"
  type        = string
}

variable "cidr_block" {
  description = "VPC用CIDRブロック"
  type        = string
  validation {
    condition     = can(regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$", var.cidr_block))
    error_message = "CIDRブロックは有効なIPv4 CIDR表記でなければなりません。"
  }
}

variable "availability_zones" {
  description = "アベイラビリティゾーンのリスト"
  type        = list(string)
}

variable "private_subnet_cidrs" {
  description = "プライベートサブネット用CIDRブロック"
  type        = list(string)
  default     = []
}

variable "enable_dns_hostnames" {
  description = "VPCでDNSホスト名を有効化"
  type        = bool
  default     = true
}

variable "tags" {
  description = "追加タグ"
  type        = map(string)
  default     = {}
}

outputs.tf:

output "vpc_id" {
  description = "VPCのID"
  value       = aws_vpc.main.id
}

output "private_subnet_ids" {
  description = "プライベートサブネットのID"
  value       = aws_subnet.private[*].id
}

output "vpc_cidr_block" {
  description = "VPCのCIDRブロック"
  value       = aws_vpc.main.cidr_block
}

ベストプラクティス

  1. モジュールにセマンティックバージョニングを使用
  2. 説明付きですべての変数を文書化
  3. examples/ディレクトリに例を提供
  4. 入力検証に検証ブロックを使用
  5. モジュール構成のために重要な属性を出力
  6. versions.tfでプロバイダーバージョンをピン
  7. 計算値にlocalsを使用
  8. count/for_eachで条件付きリソースを実装
  9. Terratestでモジュールをテスト
  10. すべてのリソースに一貫してタグ付け

モジュール構成

module "vpc" {
  source = "../../modules/aws/vpc"

  name               = "production"
  cidr_block         = "10.0.0.0/16"
  availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]

  private_subnet_cidrs = [
    "10.0.1.0/24",
    "10.0.2.0/24",
    "10.0.3.0/24"
  ]

  tags = {
    Environment = "production"
    ManagedBy   = "terraform"
  }
}

module "rds" {
  source = "../../modules/aws/rds"

  identifier     = "production-db"
  engine         = "postgres"
  engine_version = "15.3"
  instance_class = "db.t3.large"

  vpc_id     = module.vpc.vpc_id
  subnet_ids = module.vpc.private_subnet_ids

  tags = {
    Environment = "production"
  }
}

参照ファイル

  • assets/vpc-module/ - 完全なVPCモジュール例
  • assets/rds-module/ - RDSモジュール例
  • references/aws-modules.md - AWSモジュールパターン
  • references/azure-modules.md - Azureモジュールパターン
  • references/gcp-modules.md - GCPモジュールパターン

テスト

// tests/vpc_test.go
package test

import (
    "testing"
    "github.com/gruntwork-io/terratest/modules/terraform"
    "github.com/stretchr/testify/assert"
)

func TestVPCModule(t *testing.T) {
    terraformOptions := &terraform.Options{
        TerraformDir: "../examples/complete",
    }

    defer terraform.Destroy(t, terraformOptions)
    terraform.InitAndApply(t, terraformOptions)

    vpcID := terraform.Output(t, terraformOptions, "vpc_id")
    assert.NotEmpty(t, vpcID)
}

関連スキル

  • multi-cloud-architecture - アーキテクチャ決定用
  • cost-optimization - コスト効率的な設計用

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Migrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

amurata/cc-tools62025년 11월 28일 업데이트

ハイブリッドモード、段階的コンポーネント書き換え、依存性注入更新を使用してAngularJSからAngularへ移行します。AngularJSアプリケーションのアップグレード、フレームワーク移行の計画、またはレガシーAngularコードのモダナイゼーション時に使用します。

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

amurata/cc-tools62025년 11월 28일 업데이트

開発者を喜ばせる直感的でスケーラブルで保守可能なAPIを構築するために、RESTとGraphQL APIの設計原則をマスターします。新しいAPIの設計、API仕様のレビュー、またはAPI設計標準の確立時に使用してください。

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

amurata/cc-tools62025년 11월 28일 업데이트

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

amurata/cc-tools62025년 11월 28일 업데이트

Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use when architecting complex backend systems or refactoring existing applications for better maintainability.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

amurata/cc-tools62025년 11월 28일 업데이트

クリーンアーキテクチャ、ヘキサゴナルアーキテクチャ、ドメイン駆動設計を含む実証済みのバックエンドアーキテクチャパターンを実装します。複雑なバックエンドシステムの設計や、保守性向上のための既存アプリケーションのリファクタリング時に使用します。

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

amurata/cc-tools62025년 11월 28일 업데이트

amurata의 스킬 모두 보기

이 스킬의 문제 신고