# Terraform State Refactor Planner

> Plan Terraform resource migrations and generate version-specific moved blocks to prevent accidental resource destruction.

Terraform State Refactor Planner is a paid AI agent skill on Agensi by Farman J, in DevOps & Cloud. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5 (one-time purchase)
- Creator: [Farman J](https://www.agensi.io/creators/farman024)
- Category: [DevOps & Cloud](https://www.agensi.io/skills/devops-cloud)
- Version: 1.1
- Last updated: 2026-10-04
- Security: scan passed (2026-10-04); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/terraform-state-refactor-planner
- Tags: devops, terraform, infrastructure-as-code, hcl, refactoring

## About this skill

Refactoring Terraform resource names or module paths often results in unintended resource destruction and recreation. This read-only skill helps developers plan state migrations by mapping address changes and identifying the safest path forward based on your specific Terraform version. It bridges the gap between manual `state mv` commands and modern `moved` blocks.

### What it does
- **Address mapping** creates a clear bridge between old resource addresses and their new destinations.
- **Refactor classification** distinguishes between same-state moves and complex cross-state transfers.
- **Version-aware guidance** provides specific strategy recommendations based on whether you use Terraform v1.1, v1.7, or older.
- **Sanitized plan review** scans plan outputs to flag unexpected `create`, `replace`, or `destroy` actions before they hit production.
- **Snippet generation** provides draft HCL blocks for `moved`, `removed`, or `import` statements.

### How it works
1. Provide the current resource addresses and the target module or naming structure.
2. Specify your Terraform version and whether the move stays within the same state file.
3. Review the generated refactor strategy and draft HCL configuration blocks.
4. Input a sanitized plan output to verify that Terraform interprets your changes as moves rather than destructions.

### Frameworks & tools
This skill is designed for Terraform HCL and CLI workflows. It supports logic for `moved` blocks (v1.1+), `removed` blocks (v1.7+), and standard `state mv` operations.

### Why this beats prompting it yourself
Generic AI often suggests `state mv` by default, which can be dangerous in CI/CD pipelines or shared remote states. This skill enforces a "preflight" checklist that accounts for version-specific features like `moved` blocks, ensuring your refactor is declarative and auditable.

### Use cases
- Renaming existing resources to follow new organizational naming conventions.
- Moving monolithic resources into reusable sub-modules.
- Migrating resources between different state files using `removed` and `import` blocks.
- Refactoring `count` instances into `for_each` maps while preserving state.

### Known limitations
This tool is for planning only and does not execute Terraform commands or mutate state files. It does not support OpenTofu. Requires manual sanitization of plan outputs before sharing.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Terraform State Refactor Planner skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does this skill prevent Terraform from destroying my existing resources during a rename?

This skill eliminates the risk of accidental resource destruction during refactoring by generating declarative 'moved' blocks and providing a preflight checklist to ensure Terraform recognizes changes as moves rather than deletes.

### Which versions of Terraform are supported by this migration planner?

The skill supports all Terraform versions, providing tailored HCL snippets for 'moved' blocks (v1.1+), 'removed' blocks (v1.7+), and legacy 'state mv' commands for older versions.

### Does the skill automatically execute changes or modify my state files?

No, this is a read-only planning tool; it provides the HCL code and strategy, but you must manually apply the changes to your configuration to ensure full control over your infrastructure.

### What information do I need to provide to get an accurate migration plan?

Simply provide your current resource addresses, the target structure, and your Terraform version to the agent to receive a structured migration plan and HCL snippets.

### Can this skill handle complex migrations, like moving resources from a monolithic file into nested modules?

Yes, it includes specialized logic for refactoring 'count' into 'for_each' and moving resources into sub-modules while maintaining state continuity.

### What is included in the purchase of the Untitled Skill?

You receive the full skill logic and documentation for use with your preferred AI agent, including future updates to support new Terraform HCL syntax and migration features.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
