refactor-module

A guide for splitting a large Terraform configuration into reusable modules, which are organized packages of infrastructure code.

In plain words
What is it for?
Use it to analyze a monolithic configuration, design module interfaces, organize code, add tests and documentation, and plan state changes.
Why use it?
It helps create clearer inputs and outputs, reduce repetition, preserve existing Terraform state, and plan a safer migration.

Skill for Claude CodeCodex

Part of the terraform plugin — 16 skills shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/hashicorp/agent-skills/refactor-module
Any agent
npx skills add hashicorp/agent-skills --skill refactor-module
Clone the repo
git clone --depth 1 https://github.com/hashicorp/agent-skills

Made for: Claude Code, Codex.

Or install terraform, the plugin that ships this one along with the rest of its 16 skills.

Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,695 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.03695
Opus 5 $0.00014 $0.01847
Sonnet 5 $0.00006 $0.00739
Haiku 4.5 $0.00003 $0.00369

Measured 3d ago against content hash da0b9f3599ed, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactor-module scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/terraform/skills/refactor-module/SKILL.md · 561 lines

How it starts

The opening of the file, as written. The whole thing — 561 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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

2. Module Design

Interface Design
# Define clear input contract
variable "network_config" {
  description = "Network configuration parameters"
  type = object({
    cidr_block         = string
    availability_zones = list(string)
    enable_nat         = bool
  })

  validation {
    condition     = can(cidrhost(var.network_config.cidr_block, 0))
    error_message = "CIDR block must be valid IPv4 CIDR."
  }
}

# Define output contract
output "vpc_id" {
  description = "ID of the created VPC"
  value       = aws_vpc.main.id
}

output "private_subnet_ids" {
  description = "List of private subnet IDs"
  value       = { for k, v in aws_subnet.private : k => v.id }
}

Read the full file on GitHub · 561 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 561 lines · 28 tokens per session scan A da0b9f3599ed

Subscribe to this mod's changes

refactor-module is a skill published in the GitHub repository hashicorp/agent-skills (853 stars, last pushed 6d ago), licensed MPL-2.0. It adds 28 tokens to every session and 3,695 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

kagent-dev

Development guide for kagent's v1alpha3 Harness and AgentTemplate CRDs, AgentInstance gRPC control plane, upstream A2A integration, Substrate runtime provisioning, tests, generation, and PR workflow. Use for any implementation, debugging, review, or CI task in the kagent repository.

kagent-dev/kagent · 65 tokens

timoni

Use when deploying applications to Kubernetes with Timoni. Covers installing and upgrading module instances from OCI registries, composing multi-app deployments with bundles, injecting values from clusters or CI with runtimes, targeting multiple clusters, and authoring, testing, signing and publishing modules with CUE.

stefanprodan/timoni · 59 tokens

durable-objects

Create and review Cloudflare Durable Objects. Use when building stateful coordination (chat rooms, multiplayer games, booking systems), implementing RPC methods, SQLite storage, alarms, WebSockets, or reviewing DO code for best practices. Covers Workers integration, wrangler config, and testing with Vitest. Biases…

cloudflare/skills · 76 tokens

ship-web-games

Package, deploy, and verify a playable Three.js or web game. Use for release builds, asset delivery, private/public deployment, production smoke tests, browser proof, release notes, rollback readiness, and cleanup of temporary QA resources.

MengTo/Skills · 50 tokens

hyperpod-version-checker

Check and compare software component versions on SageMaker HyperPod cluster nodes - NVIDIA drivers, CUDA toolkit, cuDNN, NCCL, EFA, AWS OFI NCCL, GDRCopy, MPI, Neuron SDK (Trainium/Inferentia), Python, and PyTorch. Use when checking component versions, verifying CUDA/driver compatibility, detecting version mismatches…

awslabs/agent-plugins · 120 tokens

slo-optimize

Analyzes Grafana SLO timeline trends via gcx and produces data-backed advisory recommendations: objective tuning, alerting sensitivity review, label visibility, or window adjustments. Use when the user wants to analyze SLO performance trends and receive improvement suggestions. Trigger on phrases like "optimize my…

grafana/gcx · 127 tokens