terraform-refactoring

Refactor Terraform configurations using moved blocks to preserve state.

Updated Jan 20, 2026
One-click install
npx skills add https://github.com/Luscii/terraform-fluentbit-luscii-presets --skill terraform-refactoring
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform-refactoring
Source: https://github.com/Luscii/terraform-fluentbit-luscii-presets/tree/main/.github/skills/terraform-refactoring
Command: npx skills add https://github.com/Luscii/terraform-fluentbit-luscii-presets --skill terraform-refactoring

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps teams safely refactor Terraform configurations by introducing moved blocks to rename resources, reorganize module structure, and migrate state without destroying infrastructure, ensuring upgrades are non-disruptive.

Core Features & Use Cases

  • Safely apply moved blocks to rename resources, move modules, and adjust addresses without destroying resources.
  • Support common refactor patterns (rename resources, move resources into modules, split modules, and convert counts to for_each) with clear, irreversible moves through state updates.
  • Use case: upgrading a large Terraform project where resources must be renamed or relocated to new module paths while preserving existing infrastructure.

Quick Start

Use this skill to begin refactoring Terraform modules with moved blocks. Add moved blocks to your Terraform code, then run terraform plan to verify the changes are only address moves and not destructive changes.

Frequently Asked Questions about terraform-refactoring

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

FAQPage Schema
How do I rename Terraform resources without destroying existing infrastructure?

To rename Terraform resources without destroying infrastructure, introduce moved blocks to your configuration. This mechanism updates the state address mapping so terraform plan recognizes the changes as non-destructive moves rather than resource replacements.

What is a Terraform moved block and when should I use it?

A Terraform moved block is a configuration construct used to migrate state addresses safely. Use it when refactoring module structure, renaming resources, or adjusting addresses to ensure state migrations occur without impacting existing infrastructure.

How do I convert Terraform count to for_each without recreating resources?

Converting Terraform count to for_each without recreating resources requires using moved blocks to remap old index-based addresses to new key-based addresses. This updates the state directly, preserving existing infrastructure during the module refactor.

What Terraform version is required to use moved blocks for module refactoring?

Using moved blocks for module refactoring requires Terraform v1.1 or higher. This version introduced the moved block mechanism, which enables state migrations and non-destructive address changes across single or multi-module configurations.

Can I split a large Terraform module into smaller pieces while preserving state?

Yes, you can split a large Terraform module into smaller pieces while preserving state by applying moved blocks. This refactoring pattern safely migrates resources to new module paths without triggering destructive changes during terraform plan.

Why does terraform plan show destructive changes after renaming a resource address?

Terraform plan shows destructive changes after renaming a resource address when moved blocks are missing from the configuration. Adding moved blocks explicitly tells Terraform to migrate the state safely, changing the output from resource destruction to address moves.