refactor-module

Refactor monolithic Terraform configurations into reusable modules with state migration planning.

1|Updated Nov 1, 2021
One-click install
npx skills add https://github.com/clowa/my-setup --skill refactor-module-clowa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-module
Source: https://github.com/clowa/my-setup/tree/main/opencode/skills/terraform-refactor-module
Command: npx skills add https://github.com/clowa/my-setup --skill refactor-module-clowa

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides engineers to transform monolithic Terraform configurations into modular, reusable Terraform modules following HashiCorp's design principles and community best practices.

Core Features & Use Cases

  • Module design: define clear input and output contracts, encapsulate resources, and enable composability across environments.
  • Migration guidance: provide a step-by-step approach for migrating resources with minimal state disruption, including plan and apply steps and example migration blocks.
  • Documentation and standards: produce consistent module documentation, usage examples, and versioning strategies to support registry distribution.

Quick Start

Use the refactor-module skill to extract the VPC configuration into a reusable module, wire it into the root module, and generate a state migration plan for moving resources.

Frequently Asked Questions about refactor-module

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor monolithic Terraform configurations into reusable modules?

Refactoring monolithic Terraform configurations involves analyzing existing code, designing module interfaces with clear input and output contracts, and encapsulating resources for composability. This skill guides you through the extraction process, ensuring resources are modularized following best practices for multi-environment deployments.

What is the best way to migrate Terraform state when splitting code into modules?

Migrating Terraform state during module refactoring requires a step-by-step approach to minimize state disruption. You need to plan resource moves carefully, execute targeted plan and apply steps, and use specific migration blocks to ensure existing infrastructure aligns with the new modular structure without being recreated.

When do I need to extract Terraform resources into separate modules?

You need to extract Terraform resources into separate modules when your monolithic configuration becomes difficult to maintain or when you need to reuse infrastructure components across different environments. Encapsulating resources into modules enforces clear boundaries, enables composability, and supports registry distribution.

How do I design a Terraform module interface for multi-environment deployments?

Designing a Terraform module interface for multi-environment deployments requires defining clear input variables and output contracts. You must encapsulate environment-specific configurations behind these variables, ensuring the module remains generic enough for composability while supporting distinct environments like staging and production.

Does refactoring Terraform into modules require versioning and documentation?

Refactoring Terraform into modules requires versioning and documentation to support registry distribution and collaborative maintenance. Producing consistent module documentation, usage examples, and versioning strategies ensures that downstream consumers can safely integrate and update the modularized infrastructure code.

What are the limitations of refactoring existing Terraform code into modules?

The main limitation of refactoring existing Terraform code into modules is the risk of state disruption during migration. Moving resources into new module hierarchies requires careful state migration planning and precise execution to prevent accidentally destroying or recreating active infrastructure resources.