Skip to content

IaC · security

require-deletion-protection

iac:require-deletion-protection

Stateful resource (Cloud SQL, GKE, BigQuery, RDS, ...) must set deletion_protection = true so a stray apply cannot destroy prod data.

Code
SARJ201
Default
error
Fix
none
Languages
iac

Why

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

Fix

Set the supported literal provider deletion guard or add lifecycle { prevent_destroy = true }.

Before / after

Executed by this rule’s unit tests.

Before

Stateful database without a deletion guard

database.tf · focus
resource "google_sql_database_instance" "main" {
  name = "prod"
}

After

Stateful database with provider deletion protection

database.tf · focus
resource "google_sql_database_instance" "main" {
  name                = "prod"
  deletion_protection = true
}

Limits

  • Only the curated resource types and provider guard spellings supported by the rule are analyzed.
  • Dynamic guard expressions are rejected because their protection cannot be proven statically.