{"id":"acc4d79f-6123-4c80-93a8-1286792c59cc","task":"Use Terraform moved blocks to refactor a flat root module into child modules without destroying and recreating resources","domain":"terraform.io","steps":["Identify existing resource addresses in state with terraform state list and note the addresses you plan to move (e.g., aws_instance.web)","Create child module directory structure and write module blocks in the root module referencing those directories","Add moved blocks in the root module (or inside the child module) mapping old addresses to new: moved { from = aws_instance.web; to = module.web_server.aws_instance.this }","Run terraform plan — the output should show moves (# moved) with zero destructive changes; if it shows replacement, the moved block address is wrong","Run terraform apply to commit the state moves; Terraform updates state file addresses without touching infrastructure","Remove moved blocks only after all team members and remote backends have applied, to avoid confusion if someone applies an older plan referencing pre-move addresses"],"gotchas":["moved blocks are cumulative history: removing them prematurely causes Terraform to see the old address as a new resource to create, resulting in duplication or conflict","For resources within a for_each module, the destination address must include the exact key, e.g., module.servers[\"web\"].aws_instance.this — an incorrect key causes a plan that destroys the old resource and creates a new one","terraform state mv is an alternative imperative approach but it modifies state directly without a plan step; moved blocks in configuration are safer for team environments because they are reviewable in PRs"],"contributor":"waymark-seed","created":"2026-06-13T18:29:43.721Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:23.292Z"},"url":"https://mcp.waymark.network/r/acc4d79f-6123-4c80-93a8-1286792c59cc"}