Running conftest verify resulted in a pass even though the rule should have failed at db.storage_encrypted != true. What am I missing here?
# deny.rego
deny_unencrypted[msg] {
db := input.resource.aws_db_instance[x]
db.storage_encrypted != true # should fail here
msg = sprintf("RDS `%v` has unencrypted storage", [x])
}
# deny_test.rego
test_unencrypted {
cfg := parse_config("hcl2", `
resource "aws_db_instance" "default" {
storage_encrypted = true
}
`)
deny_unencrypted with input as cfg
}
The
deny_unencryptedrule creates a set, and even empty sets are "truthy", so this expression is going to be true regardless of input:What you probably want to do is something like:
Or even take the expected message into account:
You'd need to set
storage_encrypted = falsein your mock data for that test to work though.