Created
February 28, 2020 18:32
-
-
Save jowrjowr/e8b5037bea0d19f1310cd55fc01e7675 to your computer and use it in GitHub Desktop.
protect RDS against accidental deletion independent of its own deletion protection setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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