- Home
- Skills
- DevOps & Cloud
- Terraform State Refactor Planner
Works with the AI Agents you already use
Terraform State Refactor Planner
Plan Terraform resource migrations and generate version-specific moved blocks to prevent accidental resource destruction.
$5
Terraform State Refactor Planner
Example session with this skill installed
I need to move 'aws_instance.api_server' into a new module called 'compute'. I am running Terraform 1.5. Prepare the refactor plan and the HCL blocks.
- Read your context and instructions
- Compiled the terraform state refactor
I have analyzed the resource move from the root module to the 'compute' module. Since you are using Terraform 1.5, we can use declarative moved blocks to handle this without manual state manipulation.
Terraform Refactor Plan: api_server to module.compute
| Component | Detail |
|---|---|
| Refactor Type | Same-state Module Migration |
| Source Address | aws_instance.api_server |
| Target Address | module.compute.aws_instance.api_server |
| TF Version | 1.5 (Supports moved blocks) |
| Strategy | Declarative Refactor |
Proposed HCL Configuration
Add the following block to your configuration (typically in a moved.tf file or at the root of the module where the resource currently resides):
# Draft moved block for api_server migration
moved {
from = aws_instance.api_server
to = module.compute.aws_instance.api_server
}
Safety Checklist
- Verification: Ensure the
module "compute"block is already defined in your configuration. - [ ]
Dry Run: Run terraform plan. The output should show "0 to add, 1 to change, 0 to destroy" with a specific note that the resource is being moved.
- [ ]
Clean up: After a successful apply in all environments, these blocks can be retained for history or removed once state is unified.
Next steps
- Copy the
movedblock into yourmoved.tffile. - Run a sanitized
terraform planand verify no "destroy" actions are scheduled for the API server. - Share the plan output here if you want me to double-check the transition logic.
Connects securely to your tools. The creator never sees your data.
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, ordestroyactions before they hit production. - Snippet generation provides draft HCL blocks for
moved,removed, orimportstatements.
How it works
- Provide the current resource addresses and the target module or naming structure.
- Specify your Terraform version and whether the move stays within the same state file.
- Review the generated refactor strategy and draft HCL configuration blocks.
- 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
removedandimportblocks. - Refactoring
countinstances intofor_eachmaps 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
Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scanned
Verified clean 16 days ago
- Passed all security checks, Safe to install
Requires