[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6F5Z6KYVFAMY4R87V4ZZ0WT":3,"skill-same:01M6F5Z6KYVFAMY4R87V4ZZ0WT":65},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":34,"linkOnly":35,"markdownContent":36,"markdownBody":37,"frontMatter":38,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":45,"repositoryHtmlUrl":46,"repositoryHomepageUrl":47,"ownerHtmlUrl":48,"ownerBlogUrl":6,"ownerDescription":49,"updatedAt":50,"install":51,"resources":64},"01M6F5Z6KYVFAMY4R87V4ZZ0WT","refactor-module",null,"Transform monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fhashicorp\u002Fagent-skills\u002Frefactor-module\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33],"refactor","refactor module","module","design","best practices","terraform","ibm","hashicorp","modules","reusable","design principles","community","transform","monolithic","principles","2026-11-10 10:12:30",false,"---\nname: refactor-module\ndescription: Transform monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.\nmetadata:\n  copyright: Copyright IBM Corp. 2026\n  version: \"0.0.1\"\n---\n\n# Skill: Refactor Module\n\n## Overview\nThis skill guides AI agents in transforming monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.\n\n## Capability Statement\nThe agent will analyze existing Terraform code and systematically refactor it into well-structured modules with:\n- Clear interface contracts (variables and outputs)\n- Proper encapsulation and abstraction\n- Versioning and documentation\n- Testing frameworks\n- Migration path for existing state\n\n## Prerequisites\n- Existing Terraform configuration to refactor\n- Understanding of resource dependencies\n- Access to current state file (for migration planning)\n- Knowledge of module registry patterns\n\n## Input Parameters\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| `source_directory` | string | Yes | Path to existing Terraform configuration |\n| `module_name` | string | Yes | Name for the new module |\n| `abstraction_level` | string | No | \"simple\", \"intermediate\", \"advanced\" (default: intermediate) |\n| `preserve_state` | boolean | Yes | Whether to maintain state compatibility |\n| `target_registry` | string | No | Target module registry (local, private, public) |\n\n## Execution Steps\n\n### 1. Analysis Phase\n```markdown\n**Identify Refactoring Candidates**\n- Group resources by logical function\n- Identify repeated patterns\n- Map resource dependencies\n- Detect configuration coupling\n- Analyze variable usage patterns\n\n**Complexity Assessment**\n- Count resource relationships\n- Measure variable propagation depth\n- Identify cross-resource references\n- Evaluate state migration complexity\n```\n\n### 2. Module Design\n\n#### Interface Design\n```hcl\n# Define clear input contract\nvariable \"network_config\" {\n  description = \"Network configuration parameters\"\n  type = object({\n    cidr_block         = string\n    availability_zones = list(string)\n    enable_nat         = bool\n  })\n  \n  validation {\n    condition     = can(cidrhost(var.network_config.cidr_block, 0))\n    error_message = \"CIDR block must be valid IPv4 CIDR.\"\n  }\n}\n\n# Define output contract\noutput \"vpc_id\" {\n  description = \"ID of the created VPC\"\n  value       = aws_vpc.main.id\n}\n\noutput \"private_subnet_ids\" {\n  description = \"List of private subnet IDs\"\n  value       = { for k, v in aws_subnet.private : k => v.id }\n}\n```\n\n#### Encapsulation Strategy\n```markdown\n**What to Include in Module:**\n- Tightly coupled resources (VPC + subnets)\n- Resources with shared lifecycle\n- Configuration with clear boundaries\n\n**What to Keep Separate:**\n- Cross-cutting concerns (monitoring, tagging)\n- Resources with different lifecycles\n- Provider-specific configurations\n```\n\n### 3. Code Transformation\n\n#### Before: Monolithic Configuration\n```hcl\n# main.tf (monolithic)\nresource \"aws_vpc\" \"main\" {\n  cidr_block = \"10.0.0.0\u002F16\"\n  enable_dns_hostnames = true\n  \n  tags = {\n    Name = \"production-vpc\"\n    Environment = \"prod\"\n  }\n}\n\nresource \"aws_subnet\" \"public_1\" {\n  vpc_id            = aws_vpc.main.id\n  cidr_block        = \"10.0.1.0\u002F24\"\n  availability_zone = \"us-east-1a\"\n  \n  tags = {\n    Name = \"public-subnet-1\"\n    Type = \"public\"\n  }\n}\n\nresource \"aws_subnet\" \"public_2\" {\n  vpc_id            = aws_vpc.main.id\n  cidr_block        = \"10.0.2.0\u002F24\"\n  availability_zone = \"us-east-1b\"\n  \n  tags = {\n    Name = \"public-subnet-2\"\n    Type = \"public\"\n  }\n}\n\nresource \"aws_internet_gateway\" \"main\" {\n  vpc_id = aws_vpc.main.id\n  \n  tags = {\n    Name = \"production-igw\"\n  }\n}\n\n# ... more repetitive subnet and routing resources\n```\n\n#### After: Modular Structure\n```hcl\n# modules\u002Fvpc\u002Fmain.tf\nlocals {\n  subnet_count = length(var.availability_zones)\n}\n\nresource \"aws_vpc\" \"main\" {\n  cidr_block           = var.cidr_block\n  enable_dns_hostnames = var.enable_dns_hostnames\n  enable_dns_support   = var.enable_dns_support\n  \n  tags = merge(\n    var.tags,\n    {\n      Name = var.name\n    }\n  )\n}\n\nresource \"aws_subnet\" \"public\" {\n  for_each = var.create_public_subnets ? toset(var.availability_zones) : []\n  \n  vpc_id                  = aws_vpc.main.id\n  cidr_block              = cidrsubnet(var.cidr_block, 8, index(var.availability_zones, each.value))\n  availability_zone       = each.value\n  map_public_ip_on_launch = true\n  \n  tags = merge(\n    var.tags,\n    {\n      Name = \"${var.name}-public-${each.value}\"\n      Type = \"public\"\n    }\n  )\n}\n\nresource \"aws_internet_gateway\" \"main\" {\n  count  = var.create_public_subnets ? 1 : 0\n  vpc_id = aws_vpc.main.id\n  \n  tags = merge(\n    var.tags,\n    {\n      Name = \"${var.name}-igw\"\n    }\n  )\n}\n\n# modules\u002Fvpc\u002Fvariables.tf\nvariable \"name\" {\n  description = \"Name prefix for all resources\"\n  type        = string\n}\n\nvariable \"cidr_block\" {\n  description = \"CIDR block for the VPC\"\n  type        = string\n  \n  validation {\n    condition     = can(cidrhost(var.cidr_block, 0))\n    error_message = \"Must be a valid IPv4 CIDR block.\"\n  }\n}\n\nvariable \"availability_zones\" {\n  description = \"List of availability zones\"\n  type        = list(string)\n}\n\nvariable \"create_public_subnets\" {\n  description = \"Whether to create public subnets\"\n  type        = bool\n  default     = true\n}\n\nvariable \"enable_dns_hostnames\" {\n  description = \"Enable DNS hostnames in the VPC\"\n  type        = bool\n  default     = true\n}\n\nvariable \"enable_dns_support\" {\n  description = \"Enable DNS support in the VPC\"\n  type        = bool\n  default     = true\n}\n\nvariable \"tags\" {\n  description = \"Tags to apply to all resources\"\n  type        = map(string)\n  default     = {}\n}\n\n# modules\u002Fvpc\u002Foutputs.tf\noutput \"vpc_id\" {\n  description = \"ID of the VPC\"\n  value       = aws_vpc.main.id\n}\n\noutput \"vpc_cidr_block\" {\n  description = \"CIDR block of the VPC\"\n  value       = aws_vpc.main.cidr_block\n}\n\noutput \"public_subnet_ids\" {\n  description = \"Map of availability zones to public subnet IDs\"\n  value       = { for k, v in aws_subnet.public : k => v.id }\n}\n\noutput \"internet_gateway_id\" {\n  description = \"ID of the internet gateway\"\n  value       = try(aws_internet_gateway.main[0].id, null)\n}\n\n# Root configuration using module\nmodule \"vpc\" {\n  source = \".\u002Fmodules\u002Fvpc\"\n  \n  name               = \"production\"\n  cidr_block         = \"10.0.0.0\u002F16\"\n  availability_zones = [\"us-east-1a\", \"us-east-1b\", \"us-east-1c\"]\n  \n  tags = {\n    Environment = \"production\"\n    ManagedBy   = \"Terraform\"\n  }\n}\n```\n\n### 4. State Migration\n\n#### Generate Migration Plan\n```hcl\n# migration.tf\n# Use moved blocks for state refactoring (Terraform 1.1+)\n\nmoved {\n  from = aws_vpc.main\n  to   = module.vpc.aws_vpc.main\n}\n\nmoved {\n  from = aws_subnet.public_1\n  to   = module.vpc.aws_subnet.public[\"us-east-1a\"]\n}\n\nmoved {\n  from = aws_subnet.public_2\n  to   = module.vpc.aws_subnet.public[\"us-east-1b\"]\n}\n\nmoved {\n  from = aws_internet_gateway.main\n  to   = module.vpc.aws_internet_gateway.main[0]\n}\n```\n\n#### Manual State Migration (Pre-1.1)\n```bash\n# Generate state migration commands\nterraform state mv aws_vpc.main module.vpc.aws_vpc.main\nterraform state mv aws_subnet.public_1 'module.vpc.aws_subnet.public[\"us-east-1a\"]'\nterraform state mv aws_subnet.public_2 'module.vpc.aws_subnet.public[\"us-east-1b\"]'\nterraform state mv aws_internet_gateway.main 'module.vpc.aws_internet_gateway.main[0]'\n```\n\n### 5. Module Documentation\n\n```markdown\n# VPC Module\n\n## Overview\nCreates a VPC with configurable public and private subnets across multiple availability zones.\n\n## Features\n- Multi-AZ subnet deployment\n- Optional NAT gateway configuration\n- VPC Flow Logs integration\n- Customizable CIDR allocation\n\n## Usage\n\n\\`\\`\\`hcl\nmodule \"vpc\" {\n  source = \".\u002Fmodules\u002Fvpc\"\n  \n  name               = \"my-vpc\"\n  cidr_block         = \"10.0.0.0\u002F16\"\n  availability_zones = [\"us-east-1a\", \"us-east-1b\"]\n  \n  create_public_subnets  = true\n  create_private_subnets = true\n  enable_nat_gateway     = true\n  \n  tags = {\n    Environment = \"production\"\n  }\n}\n\\`\\`\\`\n\n## Requirements\n\n| Name | Version |\n|------|---------|\n| terraform | >= 1.5.0 |\n| aws | ~> 5.0 |\n\n## Inputs\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|----------|\n| name | Name prefix for resources | `string` | n\u002Fa | yes |\n| cidr_block | VPC CIDR block | `string` | n\u002Fa | yes |\n| availability_zones | List of AZs | `list(string)` | n\u002Fa | yes |\n\n## Outputs\n\n| Name | Description |\n|------|-------------|\n| vpc_id | VPC identifier |\n| public_subnet_ids | Map of public subnet IDs |\n| private_subnet_ids | Map of private subnet IDs |\n\n## Examples\n\nSee [examples\u002F](.\u002Fexamples\u002F) directory for complete usage examples.\n```\n\n### 6. Testing\n\nUse skill terraform-test\n\n**Test File**: A `.tftest.hcl` or `.tftest.json` file containing test configuration and run blocks that validate your Terraform configuration.\n\n**Test Block**: Optional configuration block that defines test-wide settings (available since Terraform 1.6.0).\n\n**Run Block**: Defines a single test scenario with optional variables, provider configurations, and assertions. Each test file requires at least one run block.\n\n**Assert Block**: Contains conditions that must evaluate to true for the test to pass. Failed assertions cause the test to fail.\n\n**Mock Provider**: Simulates provider behavior without creating real infrastructure (available since Terraform 1.7.0).\n\n**Test Modes**: Tests run in apply mode (default, creates real infrastructure) or plan mode (validates logic without creating resources).\n\n#### File Structure\n\nTerraform test files use the `.tftest.hcl` or `.tftest.json` extension and are typically organized in a `tests\u002F` directory. Use clear naming conventions to distinguish between unit tests (plan mode) and integration tests (apply mode):\n\n```\nmy-module\u002F\n├── main.tf\n├── variables.tf\n├── outputs.tf\n└── tests\u002F\n    ├── unit_test.tftest.hcl      # Unit test (plan mode)\n    └── integration_test.tftest.hcl  # Integration test (apply mode - creates real resources)\n```\n\n## Refactoring Patterns\n\n### Pattern 1: Resource Grouping\nExtract related resources into cohesive modules:\n- Networking (VPC, Subnets, Route Tables)\n- Compute (ASG, Launch Templates, Load Balancers)\n- Data (RDS, ElastiCache, S3)\n\n### Pattern 2: Configuration Layering\n```hcl\n# Base module with defaults\nmodule \"vpc_base\" {\n  source = \".\u002Fmodules\u002Fvpc-base\"\n  # Minimal required inputs\n}\n\n# Environment-specific wrapper\nmodule \"vpc_prod\" {\n  source = \".\u002Fmodules\u002Fvpc-production\"\n  # Inherits from base, adds prod-specific config\n}\n```\n\n### Pattern 3: Composition\n```hcl\n# Small, focused modules\nmodule \"vpc\" {\n  source = \".\u002Fmodules\u002Fvpc\"\n}\n\nmodule \"security_groups\" {\n  source = \".\u002Fmodules\u002Fsecurity-groups\"\n  vpc_id = module.vpc.vpc_id\n}\n\nmodule \"application\" {\n  source     = \".\u002Fmodules\u002Fapplication\"\n  vpc_id     = module.vpc.vpc_id\n  subnet_ids = module.vpc.private_subnet_ids\n  sg_ids     = module.security_groups.app_sg_ids\n}\n```\n\n## Common Pitfalls\n\n### 1. Over-Abstraction\n```hcl\n# ❌ Don't create overly generic modules\nvariable \"resources\" {\n  type = map(map(any))  # Too flexible, hard to validate\n}\n\n# ✅ Do use specific, typed interfaces\nvariable \"database_config\" {\n  type = object({\n    engine         = string\n    instance_class = string\n  })\n}\n```\n\n### 2. Tight Coupling\n```hcl\n# ❌ Don't couple modules through direct references\n# module A\noutput \"instance_id\" { value = aws_instance.app.id }\n\n# module B (in same config)\nresource \"aws_eip\" \"app\" {\n  instance = module.a.instance_id  # Tight coupling\n}\n\n# ✅ Do pass dependencies through root module\nmodule \"compute\" {\n  source = \".\u002Fmodules\u002Fcompute\"\n}\n\nresource \"aws_eip\" \"app\" {\n  instance = module.compute.instance_id\n}\n```\n\n### 3. State Migration Errors\nAlways test migration in non-production first:\n```bash\n# Create plan to verify no changes after migration\nterraform plan -out=migration.tfplan\n\n# Review carefully\nterraform show migration.tfplan\n\n# Apply only if plan shows no changes\nterraform apply migration.tfplan\n```\n\n## Version Control Strategy\n\n```hcl\n# Use semantic versioning for modules\nmodule \"vpc\" {\n  source  = \"git::https:\u002F\u002Fgithub.com\u002Forg\u002Fterraform-modules.git\u002F\u002Fvpc?ref=v1.2.0\"\n  version = \"~> 1.2\"\n}\n\n# Pin to specific versions in production\n# Use version ranges in development\n```\n\n## Success Criteria\n\n- [ ] Module has single, well-defined responsibility\n- [ ] All variables have descriptions and types\n- [ ] Validation rules prevent invalid configurations\n- [ ] Outputs provide sufficient information for consumers\n- [ ] Documentation includes usage examples\n- [ ] Tests verify module behavior\n- [ ] State migration completed without resource recreation\n- [ ] No plan differences after refactoring\n\n## Related Skills\n- [Terraform code generation](https:\u002F\u002Fraw.githubusercontent.com\u002Fhashicorp\u002Fagent-skills\u002Frefs\u002Fheads\u002Fmain\u002Fterraform\u002Fcode-generation\u002Fskills\u002Fterraform-style-guide\u002FSKILL.md) - Style guide for the new Terraform Module\n- [Azure Verified Modules](https:\u002F\u002Fraw.githubusercontent.com\u002Fhashicorp\u002Fagent-skills\u002Frefs\u002Fheads\u002Fmain\u002Fterraform\u002Fcode-generation\u002Fskills\u002Fazure-verified-modules\u002FSKILL.md) - Recommended module specifications for Azure\n\n## Resources\n- [Terraform Module Development](https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Flanguage\u002Fmodules\u002Fdevelop)\n- [Module Best Practices](https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Fcloud-docs\u002Fregistry\u002Fdesign)\n\n## Revision History\n\n| Version | Date | Changes |\n|---------|------|---------|\n| 1.0.0 | 2025-11-07 | Initial skill definition |\n\n","# Skill: Refactor Module\n\n## Overview\nThis skill guides AI agents in transforming monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.\n\n## Capability Statement\nThe agent will analyze existing Terraform code and systematically refactor it into well-structured modules with:\n- Clear interface contracts (variables and outputs)\n- Proper encapsulation and abstraction\n- Versioning and documentation\n- Testing frameworks\n- Migration path for existing state\n\n## Prerequisites\n- Existing Terraform configuration to refactor\n- Understanding of resource dependencies\n- Access to current state file (for migration planning)\n- Knowledge of module registry patterns\n\n## Input Parameters\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| `source_directory` | string | Yes | Path to existing Terraform configuration |\n| `module_name` | string | Yes | Name for the new module |\n| `abstraction_level` | string | No | \"simple\", \"intermediate\", \"advanced\" (default: intermediate) |\n| `preserve_state` | boolean | Yes | Whether to maintain state compatibility |\n| `target_registry` | string | No | Target module registry (local, private, public) |\n\n## Execution Steps\n\n### 1. Analysis Phase\n```markdown\n**Identify Refactoring Candidates**\n- Group resources by logical function\n- Identify repeated patterns\n- Map resource dependencies\n- Detect configuration coupling\n- Analyze variable usage patterns\n\n**Complexity Assessment**\n- Count resource relationships\n- Measure variable propagation depth\n- Identify cross-resource references\n- Evaluate state migration complexity\n```\n\n### 2. Module Design\n\n#### Interface Design\n```hcl\n# Define clear input contract\nvariable \"network_config\" {\n  description = \"Network configuration parameters\"\n  type = object({\n    cidr_block         = string\n    availability_zones = list(string)\n    enable_nat         = bool\n  })\n  \n  validation {\n    condition     = can(cidrhost(var.network_config.cidr_block, 0))\n    error_message = \"CIDR block must be valid IPv4 CIDR.\"\n  }\n}\n\n# Define output contract\noutput \"vpc_id\" {\n  description = \"ID of the created VPC\"\n  value       = aws_vpc.main.id\n}\n\noutput \"private_subnet_ids\" {\n  description = \"List of private subnet IDs\"\n  value       = { for k, v in aws_subnet.private : k => v.id }\n}\n```\n\n#### Encapsulation Strategy\n```markdown\n**What to Include in Module:**\n- Tightly coupled resources (VPC + subnets)\n- Resources with shared lifecycle\n- Configuration with clear boundaries\n\n**What to Keep Separate:**\n- Cross-cutting concerns (monitoring, tagging)\n- Resources with different lifecycles\n- Provider-specific configurations\n```\n\n### 3. Code Transformation\n\n#### Before: Monolithic Configuration\n```hcl\n# main.tf (monolithic)\nresource \"aws_vpc\" \"main\" {\n  cidr_block = \"10.0.0.0\u002F16\"\n  enable_dns_hostnames = true\n  \n  tags = {\n    Name = \"production-vpc\"\n    Environment = \"prod\"\n  }\n}\n\nresource \"aws_subnet\" \"public_1\" {\n  vpc_id            = aws_vpc.main.id\n  cidr_block        = \"10.0.1.0\u002F24\"\n  availability_zone = \"us-east-1a\"\n  \n  tags = {\n    Name = \"public-subnet-1\"\n    Type = \"public\"\n  }\n}\n\nresource \"aws_subnet\" \"public_2\" {\n  vpc_id            = aws_vpc.main.id\n  cidr_block        = \"10.0.2.0\u002F24\"\n  availability_zone = \"us-east-1b\"\n  \n  tags = {\n    Name = \"public-subnet-2\"\n    Type = \"public\"\n  }\n}\n\nresource \"aws_internet_gateway\" \"main\" {\n  vpc_id = aws_vpc.main.id\n  \n  tags = {\n    Name = \"production-igw\"\n  }\n}\n\n# ... more repetitive subnet and routing resources\n```\n\n#### After: Modular Structure\n```hcl\n# modules\u002Fvpc\u002Fmain.tf\nlocals {\n  subnet_count = length(var.availability_zones)\n}\n\nresource \"aws_vpc\" \"main\" {\n  cidr_block           = var.cidr_block\n  enable_dns_hostnames = var.enable_dns_hostnames\n  enable_dns_support   = var.enable_dns_support\n  \n  tags = merge(\n    var.tags,\n    {\n      Name = var.name\n    }\n  )\n}\n\nresource \"aws_subnet\" \"public\" {\n  for_each = var.create_public_subnets ? toset(var.availability_zones) : []\n  \n  vpc_id                  = aws_vpc.main.id\n  cidr_block              = cidrsubnet(var.cidr_block, 8, index(var.availability_zones, each.value))\n  availability_zone       = each.value\n  map_public_ip_on_launch = true\n  \n  tags = merge(\n    var.tags,\n    {\n      Name = \"${var.name}-public-${each.value}\"\n      Type = \"public\"\n    }\n  )\n}\n\nresource \"aws_internet_gateway\" \"main\" {\n  count  = var.create_public_subnets ? 1 : 0\n  vpc_id = aws_vpc.main.id\n  \n  tags = merge(\n    var.tags,\n    {\n      Name = \"${var.name}-igw\"\n    }\n  )\n}\n\n# modules\u002Fvpc\u002Fvariables.tf\nvariable \"name\" {\n  description = \"Name prefix for all resources\"\n  type        = string\n}\n\nvariable \"cidr_block\" {\n  description = \"CIDR block for the VPC\"\n  type        = string\n  \n  validation {\n    condition     = can(cidrhost(var.cidr_block, 0))\n    error_message = \"Must be a valid IPv4 CIDR block.\"\n  }\n}\n\nvariable \"availability_zones\" {\n  description = \"List of availability zones\"\n  type        = list(string)\n}\n\nvariable \"create_public_subnets\" {\n  description = \"Whether to create public subnets\"\n  type        = bool\n  default     = true\n}\n\nvariable \"enable_dns_hostnames\" {\n  description = \"Enable DNS hostnames in the VPC\"\n  type        = bool\n  default     = true\n}\n\nvariable \"enable_dns_support\" {\n  description = \"Enable DNS support in the VPC\"\n  type        = bool\n  default     = true\n}\n\nvariable \"tags\" {\n  description = \"Tags to apply to all resources\"\n  type        = map(string)\n  default     = {}\n}\n\n# modules\u002Fvpc\u002Foutputs.tf\noutput \"vpc_id\" {\n  description = \"ID of the VPC\"\n  value       = aws_vpc.main.id\n}\n\noutput \"vpc_cidr_block\" {\n  description = \"CIDR block of the VPC\"\n  value       = aws_vpc.main.cidr_block\n}\n\noutput \"public_subnet_ids\" {\n  description = \"Map of availability zones to public subnet IDs\"\n  value       = { for k, v in aws_subnet.public : k => v.id }\n}\n\noutput \"internet_gateway_id\" {\n  description = \"ID of the internet gateway\"\n  value       = try(aws_internet_gateway.main[0].id, null)\n}\n\n# Root configuration using module\nmodule \"vpc\" {\n  source = \".\u002Fmodules\u002Fvpc\"\n  \n  name               = \"production\"\n  cidr_block         = \"10.0.0.0\u002F16\"\n  availability_zones = [\"us-east-1a\", \"us-east-1b\", \"us-east-1c\"]\n  \n  tags = {\n    Environment = \"production\"\n    ManagedBy   = \"Terraform\"\n  }\n}\n```\n\n### 4. State Migration\n\n#### Generate Migration Plan\n```hcl\n# migration.tf\n# Use moved blocks for state refactoring (Terraform 1.1+)\n\nmoved {\n  from = aws_vpc.main\n  to   = module.vpc.aws_vpc.main\n}\n\nmoved {\n  from = aws_subnet.public_1\n  to   = module.vpc.aws_subnet.public[\"us-east-1a\"]\n}\n\nmoved {\n  from = aws_subnet.public_2\n  to   = module.vpc.aws_subnet.public[\"us-east-1b\"]\n}\n\nmoved {\n  from = aws_internet_gateway.main\n  to   = module.vpc.aws_internet_gateway.main[0]\n}\n```\n\n#### Manual State Migration (Pre-1.1)\n```bash\n# Generate state migration commands\nterraform state mv aws_vpc.main module.vpc.aws_vpc.main\nterraform state mv aws_subnet.public_1 'module.vpc.aws_subnet.public[\"us-east-1a\"]'\nterraform state mv aws_subnet.public_2 'module.vpc.aws_subnet.public[\"us-east-1b\"]'\nterraform state mv aws_internet_gateway.main 'module.vpc.aws_internet_gateway.main[0]'\n```\n\n### 5. Module Documentation\n\n```markdown\n# VPC Module\n\n## Overview\nCreates a VPC with configurable public and private subnets across multiple availability zones.\n\n## Features\n- Multi-AZ subnet deployment\n- Optional NAT gateway configuration\n- VPC Flow Logs integration\n- Customizable CIDR allocation\n\n## Usage\n\n\\`\\`\\`hcl\nmodule \"vpc\" {\n  source = \".\u002Fmodules\u002Fvpc\"\n  \n  name               = \"my-vpc\"\n  cidr_block         = \"10.0.0.0\u002F16\"\n  availability_zones = [\"us-east-1a\", \"us-east-1b\"]\n  \n  create_public_subnets  = true\n  create_private_subnets = true\n  enable_nat_gateway     = true\n  \n  tags = {\n    Environment = \"production\"\n  }\n}\n\\`\\`\\`\n\n## Requirements\n\n| Name | Version |\n|------|---------|\n| terraform | >= 1.5.0 |\n| aws | ~> 5.0 |\n\n## Inputs\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|----------|\n| name | Name prefix for resources | `string` | n\u002Fa | yes |\n| cidr_block | VPC CIDR block | `string` | n\u002Fa | yes |\n| availability_zones | List of AZs | `list(string)` | n\u002Fa | yes |\n\n## Outputs\n\n| Name | Description |\n|------|-------------|\n| vpc_id | VPC identifier |\n| public_subnet_ids | Map of public subnet IDs |\n| private_subnet_ids | Map of private subnet IDs |\n\n## Examples\n\nSee [examples\u002F](.\u002Fexamples\u002F) directory for complete usage examples.\n```\n\n### 6. Testing\n\nUse skill terraform-test\n\n**Test File**: A `.tftest.hcl` or `.tftest.json` file containing test configuration and run blocks that validate your Terraform configuration.\n\n**Test Block**: Optional configuration block that defines test-wide settings (available since Terraform 1.6.0).\n\n**Run Block**: Defines a single test scenario with optional variables, provider configurations, and assertions. Each test file requires at least one run block.\n\n**Assert Block**: Contains conditions that must evaluate to true for the test to pass. Failed assertions cause the test to fail.\n\n**Mock Provider**: Simulates provider behavior without creating real infrastructure (available since Terraform 1.7.0).\n\n**Test Modes**: Tests run in apply mode (default, creates real infrastructure) or plan mode (validates logic without creating resources).\n\n#### File Structure\n\nTerraform test files use the `.tftest.hcl` or `.tftest.json` extension and are typically organized in a `tests\u002F` directory. Use clear naming conventions to distinguish between unit tests (plan mode) and integration tests (apply mode):\n\n```\nmy-module\u002F\n├── main.tf\n├── variables.tf\n├── outputs.tf\n└── tests\u002F\n    ├── unit_test.tftest.hcl      # Unit test (plan mode)\n    └── integration_test.tftest.hcl  # Integration test (apply mode - creates real resources)\n```\n\n## Refactoring Patterns\n\n### Pattern 1: Resource Grouping\nExtract related resources into cohesive modules:\n- Networking (VPC, Subnets, Route Tables)\n- Compute (ASG, Launch Templates, Load Balancers)\n- Data (RDS, ElastiCache, S3)\n\n### Pattern 2: Configuration Layering\n```hcl\n# Base module with defaults\nmodule \"vpc_base\" {\n  source = \".\u002Fmodules\u002Fvpc-base\"\n  # Minimal required inputs\n}\n\n# Environment-specific wrapper\nmodule \"vpc_prod\" {\n  source = \".\u002Fmodules\u002Fvpc-production\"\n  # Inherits from base, adds prod-specific config\n}\n```\n\n### Pattern 3: Composition\n```hcl\n# Small, focused modules\nmodule \"vpc\" {\n  source = \".\u002Fmodules\u002Fvpc\"\n}\n\nmodule \"security_groups\" {\n  source = \".\u002Fmodules\u002Fsecurity-groups\"\n  vpc_id = module.vpc.vpc_id\n}\n\nmodule \"application\" {\n  source     = \".\u002Fmodules\u002Fapplication\"\n  vpc_id     = module.vpc.vpc_id\n  subnet_ids = module.vpc.private_subnet_ids\n  sg_ids     = module.security_groups.app_sg_ids\n}\n```\n\n## Common Pitfalls\n\n### 1. Over-Abstraction\n```hcl\n# ❌ Don't create overly generic modules\nvariable \"resources\" {\n  type = map(map(any))  # Too flexible, hard to validate\n}\n\n# ✅ Do use specific, typed interfaces\nvariable \"database_config\" {\n  type = object({\n    engine         = string\n    instance_class = string\n  })\n}\n```\n\n### 2. Tight Coupling\n```hcl\n# ❌ Don't couple modules through direct references\n# module A\noutput \"instance_id\" { value = aws_instance.app.id }\n\n# module B (in same config)\nresource \"aws_eip\" \"app\" {\n  instance = module.a.instance_id  # Tight coupling\n}\n\n# ✅ Do pass dependencies through root module\nmodule \"compute\" {\n  source = \".\u002Fmodules\u002Fcompute\"\n}\n\nresource \"aws_eip\" \"app\" {\n  instance = module.compute.instance_id\n}\n```\n\n### 3. State Migration Errors\nAlways test migration in non-production first:\n```bash\n# Create plan to verify no changes after migration\nterraform plan -out=migration.tfplan\n\n# Review carefully\nterraform show migration.tfplan\n\n# Apply only if plan shows no changes\nterraform apply migration.tfplan\n```\n\n## Version Control Strategy\n\n```hcl\n# Use semantic versioning for modules\nmodule \"vpc\" {\n  source  = \"git::https:\u002F\u002Fgithub.com\u002Forg\u002Fterraform-modules.git\u002F\u002Fvpc?ref=v1.2.0\"\n  version = \"~> 1.2\"\n}\n\n# Pin to specific versions in production\n# Use version ranges in development\n```\n\n## Success Criteria\n\n- [ ] Module has single, well-defined responsibility\n- [ ] All variables have descriptions and types\n- [ ] Validation rules prevent invalid configurations\n- [ ] Outputs provide sufficient information for consumers\n- [ ] Documentation includes usage examples\n- [ ] Tests verify module behavior\n- [ ] State migration completed without resource recreation\n- [ ] No plan differences after refactoring\n\n## Related Skills\n- [Terraform code generation](https:\u002F\u002Fraw.githubusercontent.com\u002Fhashicorp\u002Fagent-skills\u002Frefs\u002Fheads\u002Fmain\u002Fterraform\u002Fcode-generation\u002Fskills\u002Fterraform-style-guide\u002FSKILL.md) - Style guide for the new Terraform Module\n- [Azure Verified Modules](https:\u002F\u002Fraw.githubusercontent.com\u002Fhashicorp\u002Fagent-skills\u002Frefs\u002Fheads\u002Fmain\u002Fterraform\u002Fcode-generation\u002Fskills\u002Fazure-verified-modules\u002FSKILL.md) - Recommended module specifications for Azure\n\n## Resources\n- [Terraform Module Development](https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Flanguage\u002Fmodules\u002Fdevelop)\n- [Module Best Practices](https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Fcloud-docs\u002Fregistry\u002Fdesign)\n\n## Revision History\n\n| Version | Date | Changes |\n|---------|------|---------|\n| 1.0.0 | 2025-11-07 | Initial skill definition |\n\n",{"name":5,"metadata":39,"description":7},{"version":40,"copyright":41},"0.0.1","Copyright IBM Corp. 2026","main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Fhashicorp\u002Fagent-skills\u002Frefactor-module",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":52,"prompt":62,"zipAvailable":63},[53,56,59],{"tool":54,"command":55},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill refactor-module",{"tool":57,"command":58},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill refactor-module",{"tool":60,"command":61},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill refactor-module","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fhashicorp\u002Fagent-skills\u002Frefactor-module\u002FSKILL.md",true,[],[66,75,84,93,99,105],{"skillNo":67,"name":68,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":34},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[72,73,74],"model","model hierarchy","model hierarchy skill",{"skillNo":76,"name":77,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":34},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[81,82,83],"MCP","zoom","zoom mcp",{"skillNo":85,"name":86,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":34},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[90,91,92,82],"sdk","zoom apps sdk","apps",{"skillNo":94,"name":95,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":34},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[95],{"skillNo":100,"name":101,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":34},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[101],{"skillNo":106,"name":107,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":34},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[107]]