hashicorp avatar

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-code

Installs 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

Repository
github.com/hashicorp/agent-skills
Categories
DevOps & CI/CD, Code Review & Quality, AI & Agent Building, Cloud & Infrastructure, Design & UI/UX

More from hashicorp/agent-skills

All 16
1assistant-ui avatartoolsassistant-ui/skillsRegisters LLM tools and renders custom tool-call UI in assistant-ui (@assistant-ui/react). Covers the current authoring model: a "use generative" file exporting6.5Kskills.sh installs
2affaan-m avatarfrontend-slidesaffaan-m/eccCreate stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PP6.5Kskills.sh installs
3aws avatarexporting-rds-to-s3aws/agent-toolkit-for-awsExports Amazon RDS or Aurora database snapshots to Amazon S3 in Apache Parquet format for analytics, backup, or data migration. Handles snapshot selection or cr6.5Kskills.sh installs
4jeffallan avatarfastapi-expertjeffallan/claude-skillsUse when building high-performance async Python APIs with FastAPI and Pydantic V2. Invoke to create REST endpoints, define Pydantic models, implement authentica6.4Kskills.sh installs
5affaan-m avatare2e-testingaffaan-m/eccPlaywright E2E testing patterns, Page Object Model, configuration, CI/CD integration, artifact management, and flaky test strategies.6.4Kskills.sh installs
6trailofbits avatarsarif-parsingtrailofbits/skillsParses and processes SARIF files from static analysis tools like CodeQL, Semgrep, or other scanners. Triggers on "parse sarif", "read scan results", "aggregate 6.4Kskills.sh installs