Refactor Module
Transform monolithic Terraform configurations into reusable, maintainable modules...
Install
npx skills add hashicorp/agent-skills --skill refactor-module -g -a claude-code -y- Repository
- hashicorp/agent-skills911
- Category
- Design
- Updated
- 7d ago
- License
- MPL-2.0
- Context cost
- Mediumabout 3,000 tokens
- Runs scripts
- No, instructions only
What it does
Transform monolithic Terraform configurations into reusable, maintainable modules following HashiCorp's module design principles and community best practices.
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 |
|---|---|---|---|
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) |
Execution Steps
1. Analysis Phase
**Identify Refactoring Candidates**
- Group resources by logical function
- Identify repeated patterns
- Map resource dependencies
- Detect configuration coupling
- Analyze variable usage patterns
**Complexity Assessment**
- Count resource relationships
- Measure variable propagation depth
- Identify cross-resource references
- Evaluate state migration complexity


