Can't catch undefined values in functions #607
Unanswered
roco1234
asked this question in
OPA and Rego
Replies: 1 comment 5 replies
-
I'll pick out one part of the puzzle and you'll probably able to fill in the rest 😃
security_group_ingress_has_description(sg) if not sg.SecurityGroupIngress # if there's no Ingress, it's OK
security_group_ingress_has_description(sg) if {
sg.SecurityGroupIngress.Description != ""
} Two rule bodies mean OR. So you get that it's either not there, or it is there and has a description. You could now refactor it to take the field as argument: security_group_field_has_description(sg, field) if not sg[field] # if there's no such field, it's OK
security_group_field_has_description(sg, field) if {
sg[field].Description != ""
} then you can use it like this: allow if {
security_group.GroupDescription
security_group_field_has_description(security_group, "SecurityGroupIngress")
security_group_field_has_description(security_group, "SecurityGroupEgress")
} or, with allow if {
security_group.GroupDescription
every field in {"SecurityGroupIngress", "SecurityGroupEgress"} {
security_group_field_has_description(security_group, field)
}
} |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to write a policy to check that
GroupDescription
is defined and that IFSecurityGroupEgress
AND/ORSecurityGroupIngress
is defined, they both haveDescription
definedyaml
In this example the template check fails because
all_rules_have_descriptions(security_group.SecurityGroupIngress)
fails. Is there something I can do to get undefined to pass? I have also tried== null
,count(rules) == 0
Or do I have to just explicitly check every scenario where ingress could be set but egress isn't etc
Beta Was this translation helpful? Give feedback.
All reactions