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.
More on Refactoring, Migration and Drift
What is your workflow for refactoring Terraform safely?IntermediateHow do you rename a resource inside a shared module without breaking consumers?AdvancedHow do you split one state into two without downtime?AdvancedHow do you merge two states?IntermediateHow do you import a large existing environment efficiently?IntermediateHow do you upgrade a major version of the AWS provider?Advanced