Interview Prep/Terraform/Refactoring, Migration and Drift

A resource was replaced by mistake and the database is gone. What now, and how do you prevent it?

AdvancedProductionRefactoring, Migration and Drift
Answer

Restore from the latest snapshot or point-in-time backup into a new instance, import it into state at the right address (or let Terraform create it from snapshot_identifier), and repoint applications. Prevention: deletion_protection = true, prevent_destroy, skip_final_snapshot = false with a final_snapshot_identifier, plan checks that fail on deletes of stateful types and approvals for replacements.

All Terraform questions Roadmap: Terraform in production

More on Refactoring, Migration and Drift