Agent skill · hashicorp
refactor-module
Transform monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.
What it needs
About 8k tokens when loaded.
What this skill does
Skill: Refactor Module Overview This skill guides AI agents in transforming monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices. Capability Statement The agent will analyze existing Terraform code and systematically refactor it into well-structured modules with: Clear interface contracts (variables and outputs) Proper encapsulation and abstraction Versioning and documentation Testing frameworks Migration path for existing state Prerequisites Existing Terraform configuration to refactor Understanding of resource dependencies Access to inspect current state via terraform state list / terraform show -json (for migration planning) Knowledge of module registry patterns Input Parameters Parameter Type Required Description ----------- ------ ---------- ------------- sourcedirectory string Yes Path to existing Terraform configuration modulename string Yes Name for the new module abstractionlevel string No "simple", "intermediate", "advanced" (default: intermediate) preservestate boolean Yes Whether to maintain state compatibility targetregistry string No Target module registry (local, private, public) Execution Steps 1. Analysis Phase 2. Module Design Interface Design Encapsulation Strategy 3. Code Transformation Before: Monolithic Configuration After: Modular Structure 4. State Migration Inspecting Current State Before writing moved blocks or state mv commands, inspect the current state to map existing resource addresses. Prefer the documented, stable, and more token-efficient commands over reading the raw state file: terraform show -json requires providers to be installed (terraform init), since it renders values against provider schemas. Fall back to the raw state (terraform state pull / terraform.tfstate) only when providers aren't available and init can't run, you need only coarse info (addresses, outputs, serial/lineage), or you must avoid executing Terraform. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills hashicorp/refactor-module--5e28cb