terraform/module-generation/skills/refactor-module/SKILL.md
Transform monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.
npx skillsauth add lidge-jun/cli-jaw-skills refactor-moduleInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| source_directory | string | Yes | Path to existing Terraform configuration |
| module_name | string | Yes | Name for the new module |
| abstraction_level | string | No | "simple", "intermediate", "advanced" (default: intermediate) |
| preserve_state | boolean | Yes | Whether to maintain state compatibility |
| target_registry | string | No | Target module registry (local, private, public) |
Define typed input contracts with validation and descriptive outputs:
variable "network_config" {
description = "Network configuration parameters"
type = object({
cidr_block = string
availability_zones = list(string)
enable_nat = bool
})
validation {
condition = can(cidrhost(var.network_config.cidr_block, 0))
error_message = "CIDR block must be valid IPv4 CIDR."
}
}
output "vpc_id" {
description = "ID of the created VPC"
value = aws_vpc.main.id
}
output "private_subnet_ids" {
description = "List of private subnet IDs"
value = { for k, v in aws_subnet.private : k => v.id }
}
Include in module:
Keep separate:
Extract hardcoded values into variables, replace repeated resources with for_each, and use merge() for tag propagation.
See references/transformation-example.md for a complete monolithic→modular VPC refactoring example.
Use moved blocks (Terraform 1.1+) for declarative state migration. For older versions, use terraform state mv commands.
See references/state-migration.md for examples of both approaches.
Verify migration in non-production first:
terraform plan -out=migration.tfplan # expect no changes
terraform show migration.tfplan # review carefully
terraform apply migration.tfplan # apply only if clean
Use skill terraform-test. Organize tests in a tests/ directory:
my-module/
├── main.tf
├── variables.tf
├── outputs.tf
└── tests/
├── unit_test.tftest.hcl # plan mode
└── integration_test.tftest.hcl # apply mode (creates real resources)
Each module needs a README with: Overview, Usage example, Requirements, Inputs table, Outputs table.
See references/module-documentation-template.md for the standard template.
Extract related resources into cohesive modules:
module "vpc_base" {
source = "./modules/vpc-base"
# Minimal required inputs
}
module "vpc_prod" {
source = "./modules/vpc-production"
# Inherits from base, adds prod-specific config
}
Build complex infrastructure from small, focused modules:
module "vpc" {
source = "./modules/vpc"
}
module "security_groups" {
source = "./modules/security-groups"
vpc_id = module.vpc.vpc_id
}
module "application" {
source = "./modules/application"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
sg_ids = module.security_groups.app_sg_ids
}
Use specific, typed interfaces. map(map(any)) prevents validation and obscures intent.
# Prefer this
variable "database_config" {
type = object({
engine = string
instance_class = string
})
}
Pass dependencies through the root module rather than coupling modules directly, keeping modules independently testable.
Run terraform plan after migration and confirm zero changes before applying to production.
# Pin module versions with semantic versioning
module "vpc" {
source = "git::https://github.com/org/terraform-modules.git//vpc?ref=v1.2.0"
}
Pin exact versions in production; use version ranges in development.
| Version | Date | Changes | |---------|------|---------| | 1.0.0 | 2025-11-07 | Initial skill definition |
development
Goal execution guidelines with PABCD integration, verification tiers, documentation workflow, and AI-driven planning
tools
A CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
development
Use this skill any time a spreadsheet file is the primary input or output (.xlsx, .xlsm, .csv, .tsv). This includes: creating, reading, editing, analyzing, or formatting spreadsheets; cleaning messy tabular data; converting between formats; and data visualization with charts. Also use for pandas-based data analysis when the deliverable is a spreadsheet. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration.
tools
Use this skill when the user wants to build a financial model, 3-statement model, DCF valuation, cap table, scenario analysis, or financial projections in Excel. Trigger on: 'financial model', '3-statement model', 'DCF', 'cap table', 'pro forma', 'projections', 'sensitivity analysis', 'waterfall', 'debt schedule', 'break-even', 'discounted cash flow', 'capitalization table', 'fundraising model', 'WACC calculation', 'scenario analysis model'. Input is a text prompt with assumptions. Output is a single .xlsx file with formula-driven, interconnected statement sheets.