Skip to content

Instantly share code, notes, and snippets.

@jowrjowr
Created February 28, 2020 18:32
Show Gist options
  • Save jowrjowr/e8b5037bea0d19f1310cd55fc01e7675 to your computer and use it in GitHub Desktop.
Save jowrjowr/e8b5037bea0d19f1310cd55fc01e7675 to your computer and use it in GitHub Desktop.
protect RDS against accidental deletion independent of its own deletion protection setting
data "aws_iam_policy_document" "deletion_protection" {
statement {
sid = "DenyRDSDeletion"
effect = "Deny"
actions = [
"rds:DeleteDBInstance",
"rds:DeleteDBCluster"
]
resources = ["*"]
condition {
test = "StringNotEquals"
variable = "rds:db-tag/deletion_protection"
values = [
false
]
}
}
}
resource "aws_iam_policy" "deletion_protection" {
name = "Deny-accidental-deletion"
description = "Deletion protection for certain resources"
policy = data.aws_iam_policy_document.deletion_protection.json
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment