Skip to content

require-deletion-protection

Warn when a curated stateful Terraform resource lacks a proven provider-native deletion guard or literal lifecycle destroy guard.

Why

Stateful services can lose durable production data when an accidental Terraform change or destroy is allowed to delete the backing resource.

Fix

Use the exact provider guard supported by that resource. Where none exists, consider lifecycle { prevent_destroy = true }, which no longer protects the resource after its block is removed.

Examples

Before — flagged Cloud SQL child database uses its deletable default
database.tf
resource "google_sql_database" "app" {
name = "app"
instance = google_sql_database_instance.main.name
}
After — preferred Cloud SQL child database uses its provider guard
database.tf
resource "google_sql_database" "app" {
name = "app"
instance = google_sql_database_instance.main.name
deletion_policy = "PREVENT"
}