acedergren/agentic-tools/refactor-module
Claude Code and agent skill by acedergren/agentic-tools
- community
Checking that the SKILL.md file is still in the repository.
Use when deciding whether to extract Terraform code into a reusable module, determining module boundaries, or migrating state after modularization. Covers the refactoring decision (modularize vs inline), anti-patterns causing module sprawl, and state migration risk. Keywords: terraform module, refactor terraform, module boundaries, terraform abstraction, module sprawl, state migration, terraform state mv. Triggers on "refactor Terraform module" or "decide module boundary".
Install
npx vskill@latest install acedergren/agentic-tools/refactor-moduleSKILL.md
Terraform Module Refactoring - Decision Expert
When to Use
Load this skill when the user request matches the frontmatter description for Terraform Module Refactoring - Decision Expert.
Assumption: You know Terraform syntax. This covers when to modularize vs keep inline.
NEVER
- Never modularize on first usage — wait for the third real instance; premature abstraction locks in the wrong seam.
- Never expose module variables 1:1 with resource arguments — that's not abstraction, it's indirection (the Leaky Abstraction trap).
- Never refactor inline resources to a module without running
terraform state mvfirst — Terraform will plan to destroy and recreate every resource. - Never create a module for frequently-changing code — module API changes cascade across all consumers.
- Never skip
terraform state pull > backup.tfstatebefore any state migration.
The Core Decision
Break-even: Module worth it at 4+ identical usages + stable API + compliance need. Time cost: Simple module = 2 hours. Complex with state migration = 2 days planning + 4 hours execution.
Before Extracting: Strategic Check
| Question | Threshold | Decision | |
|---|---|---|---|
| How many usages? | <3 | Keep inline | |
| How identical? | <50% same | Use locals, not module | |
| Change frequency | Weekly | DON'T (unstable API) | |
| Test coverage | <50% | TOO RISKY (breaking changes uncaught) | |
| Consumer count | 10+ | Every change = 10 PRs, plan migration carefully |
Anti-Patterns
Leaky Abstraction (most common)
Signal: Module variables match resource arguments 1:1 (50 variables for a VPC module).
Fix: Expose intent, not resource config:
Test: "Does the module consumer need AWS VPC knowledge to use this?" YES = leaky abstraction.
State Migration Trap (most dangerous)
Moving inline resources into a module changes state addresses: aws_vpc.main → module.network.aws_vpc.main
Terraform reads this as "destroy old, create new" — no warning, identical config, production outage.
Load `references/error-recovery.md` if already applied and resources were destroyed.
Module Version Hell
Signal: grep -r 'source.*?ref=' . | sort | uniq -c shows 3+ active versions.
Fix: Breaking changes require major version + 6-month deprecation + migration guide. Or eliminate versions entirely with monorepo workspace protocol.
Module Boundaries
Good: VPC + subnets + route tables + NAT gateway (one cohesive networking unit) Bad: Just VPC (consumer must wire subnets manually)
Prefer composition (small focused modules wired together) over monolithic (one module creates everything). Exception: compliance modules that must enforce standards together.
Refactoring Checklist
grep -r "resource \"aws_s3_bucket\"" .— confirm 3+ usages before touching anythingdiff app1/s3.tf app2/s3.tf— confirm >80% identical, not superficially similar- Design interface around intent (
bucket_type = "data"|"logs"|"artifacts"), not resource args terraform state pull > backup.tfstate— always before state movesterraform state mv <old-address> <new-address>— one resource at a timeterraform plan— must show "No changes" before proceeding
When to Load References
Load `references/error-recovery.md` when:
- State migration already applied and caused destroy/recreate
- Module has grown to 10+ boolean toggles and needs redesign
- Multiple module versions causing maintenance coordination problems
Do NOT load for:
- Basic modularization decisions (use Core Decision tree above)
- Single resource state moves (use Refactoring Checklist above)
- Terraform syntax help (see official docs)
Arguments
$ARGUMENTS: Optional user-provided target, path, environment, symptom, or constraint. When empty, infer the narrowest safe scope from the current repository context and ask only if multiple high-impact choices remain.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/refactor-module/SKILL.md
Popularity
- Repository stars
- 10
- Repository forks
- 2
- 7-day trend score
- 12
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 12 Apr 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/acedergren/agentic-tools/refactor-module)