Interview Prep/Terraform/Import, Already Exists and State Surgery

You need to move a resource from stack A's state to stack B's state. `terraform state mv` with `-state-out` isn't working with the S3 backend.

AdvancedTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → -state / -state-out work on local files only; with remote backends you must use pull/push or a declarative approach.

Diagnose → The command complains about local state options or updates only a local file.

Fix → The safest approach in 1.7+: in stack A add removed { from = aws_sqs_queue.jobs lifecycle { destroy = false } } and apply; in stack B add the resource plus an import block and apply. No hand-edited state, and both steps are reviewed plans.

Prevent → Plan stack boundaries early; when moving, always use the removed + import pattern.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery