# generate_iac > Infrastructure as Codeの設定を生成する。Terraform、CloudFormation、Kubernetesマニフェストを作成。Use when creating infrastructure as code configurations. - Author: kaz - Repository: cocomomojo/codecepsjs-test - Version: 20260127204427 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/cocomomojo/codecepsjs-test - Web: https://mule.run/skillshub/@@cocomomojo/codecepsjs-test~generate_iac:20260127204427 --- --- name: generate_iac description: Infrastructure as Codeの設定を生成する。Terraform、CloudFormation、Kubernetesマニフェストを作成。Use when creating infrastructure as code configurations. --- ## Description AWS の構成を Terraform/CDK で生成する。 ベストプラクティスに沿ったインフラコードを自動生成し、セキュリティと運用性を重視。 ## Inputs - architecture_requirements: アーキテクチャ要件 - cloud_provider: クラウドプロバイダー(AWS, GCP, Azure) - environment: 環境(dev, staging, prod) - security_requirements: セキュリティ要件 - budget_constraints: 予算制約 ## Output - Terraform設定ファイル - 環境別variables設定 - デプロイ手順書 - コスト試算 ## Behavior - ベストプラクティスに沿った IaC を生成 - セキュリティ設定(IAM, VPC, Security Groups)を適切に配置 - 環境分離とタグ管理を実装 - コスト最適化を考慮したリソース設定 - 監視とログ設定を含める ## IaC Templates ### ECS Fargate with ALB ```hcl # VPC Configuration resource "aws_vpc" "main" { cidr_block = var.vpc_cidr enable_dns_hostnames = true enable_dns_support = true tags = { Name = "${var.project_name}-vpc" Environment = var.environment } } resource "aws_subnet" "public" { count = 2 vpc_id = aws_vpc.main.id cidr_block = var.public_subnet_cidrs[count.index] availability_zone = data.aws_availability_zones.available.names[count.index] map_public_ip_on_launch = true tags = { Name = "${var.project_name}-public-subnet-${count.index + 1}" Type = "Public" } } # ECS Cluster resource "aws_ecs_cluster" "main" { name = "${var.project_name}-cluster" capacity_providers = ["FARGATE"] default_capacity_provider_strategy { capacity_provider = "FARGATE" weight = 100 } } # Task Definition resource "aws_ecs_task_definition" "app" { family = "${var.project_name}-task" network_mode = "awsvpc" requires_compatibilities = ["FARGATE"] cpu = var.task_cpu memory = var.task_memory execution_role_arn = aws_iam_role.ecs_execution_role.arn container_definitions = jsonencode([ { name = var.project_name image = "${var.ecr_repository_url}:latest" essential = true portMappings = [ { containerPort = var.container_port protocol = "tcp" } ] logConfiguration = { logDriver = "awslogs" options = { "awslogs-group" = aws_cloudwatch_log_group.app.name "awslogs-region" = data.aws_region.current.name "awslogs-stream-prefix" = "ecs" } } } ]) } ``` ### RDS with Security ```hcl # RDS Subnet Group resource "aws_db_subnet_group" "main" { name = "${var.project_name}-db-subnet-group" subnet_ids = aws_subnet.private[*].id tags = { Name = "${var.project_name} DB subnet group" } } # RDS Instance resource "aws_db_instance" "main" { identifier = "${var.project_name}-db" engine = "postgres" engine_version = "14.9" instance_class = var.db_instance_class allocated_storage = var.db_allocated_storage max_allocated_storage = var.db_max_allocated_storage storage_encrypted = true db_name = var.db_name username = var.db_username password = var.db_password vpc_security_group_ids = [aws_security_group.rds.id] db_subnet_group_name = aws_db_subnet_group.main.name backup_retention_period = var.backup_retention_period backup_window = "03:00-04:00" maintenance_window = "sun:04:00-sun:05:00" skip_final_snapshot = var.environment == "dev" deletion_protection = var.environment == "prod" tags = { Name = "${var.project_name}-database" Environment = var.environment } } ```