create_before_destroy and prevent_destroy
Scenario: A broad cleanup plan includes the production data store, and an engineer notices only after approval.
create_before_destroy changes replacement ordering. prevent_destroy rejects plans that would destroy a protected instance while the lifecycle rule remains in configuration. It is a tripwire, not a backup and not protection from deleting the configuration plus state or using the provider console. Lifecycle decisions can propagate through dependencies and should be used selectively.
Analogy: A safety catch reduces accidental discharge; it does not make a weapon harmless or replace training.
A worked configuration
lifecycle {
create_before_destroy = true
prevent_destroy = true
}
Use provider-native deletion protection, backups, least privilege, and policy controls alongside Terraform lifecycle rules. Document the exceptional process for removing protection so emergencies do not produce improvised state surgery.
Note: Treat the plan as a change contract: understand every create, update, replacement, and destroy before approving it.
Goal: Reinforce this lesson in the tf-lifecycle-safety Terraform lab. Open/labs/terraformand choose slugtf-lifecycle-safety; the lab runs real Terraform against the offline FakeCloud provider.