
Refactor Module
This tackles the refactoring work that makes Terraform configs actually maintainable. It guides you through breaking monolithic configurations into proper modules with clear variable contracts, moving from repetitive subnet declarations to for_each patterns, and handling the state migration so nothing breaks in production. The skill includes moved blocks for Terraform 1.1+ or generates manual state mv commands for older versions. What I like here is the focus on encapsulation decisions, like explicitly calling out what belongs in a module versus what to keep separate based on lifecycle and coupling. If you've got a main.tf that's grown into hundreds of lines of copy-pasted resource blocks, this gives you a structured path to module-ize it without losing your existing infrastructure state.
- skills.sh installs
- 6.6K
- GitHub stars
- 924
- last updated
- Aug 21, 2026
Install
$ npx -y skills add hashicorp/agent-skills --skill refactor-module --agent claude-codeInstalls into .claude/skills of the current project.
Files
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
Sponsors
Details
More from hashicorp/agent-skills
All 16- Terraform Stacks5.8K
- Terraform Search Import5.1K
- Provider Resources4.2K
- New Terraform Provider4K
- Provider Actions4K
- Run Acceptance Tests3.8K
- Azure Verified Modules3.4K
- Provider Test Patterns3.4K
- Provider Docs3.3K
- Aws Ami Builder3.3K
- Push To Registry3.1K
- Azure Image Builder2.8K
- Windows Builder2.8K
- Terraform Style Guide13.2K
- Terraform Test9.2K