What if one wrong click could erase your entire cloud setup forever?
Why Prevent_destroy lifecycle rule in Terraform? - Purpose & Use Cases
Imagine you manage a cloud server that runs your website. One day, you accidentally delete it while cleaning up resources because you forgot which one was critical.
Manually tracking which resources are important is hard. Mistakes happen easily, causing downtime and lost data. Fixing these mistakes takes time and can be costly.
The prevent_destroy rule in Terraform stops important resources from being deleted by mistake. It acts like a safety lock, so you must consciously remove the lock before deleting.
resource "aws_instance" "web" { # no protection, can be deleted anytime }
resource "aws_instance" "web" { lifecycle { prevent_destroy = true } }
This rule lets you protect critical cloud resources from accidental deletion, keeping your services safe and reliable.
A company uses prevent_destroy on their database server resource to avoid accidental removal during updates, preventing data loss and downtime.
Manual deletion risks breaking important cloud resources.
prevent_destroy adds a safety lock to stop accidental deletes.
It helps keep your cloud infrastructure stable and secure.