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

Import finished, but now `terraform plan` shows a forced replacement on the imported resource.

AdvancedTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → An argument in code that forces replacement differs from reality: availability_zone, subnet_id, name, engine, kms_key_id, or user_data with user_data_replace_on_change = true.

Diagnose → terraform plan | grep -B2 '# forces replacement', then terraform state show <addr> to see real values.

Fix → Change code to match the imported values exactly. Never apply an import PR that shows a replace.

Prevent → Add a CI rule: PRs containing import blocks must show zero delete and zero update actions.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery