Check if array exists #328
Unanswered
gituser022
asked this question in
Terraform
Replies: 1 comment 2 replies
-
Hey, 🙂 How about something like this: https://play.openpolicyagent.org/p/Ecmh6Q2FeJ It's common when writing rules to handle different cases with different deny blocks as I have done here. Hope that makes sense. |
Beta Was this translation helpful? Give feedback.
2 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.
-
Hello,
Iam struggling to write OPA policy rule that should check an element of an array but the array itself is optional.
Input:
{ "load_balancer":[{ "target_group_arn":true }] }
Policy Rule:
deny[message] { message := "Target ARN is missing" lb:= [rule | rule:= input.load_balancer[_] ; rule.target_group_arn ] ???? }
I am not sure how could I proceed. If I simply say count(lb) > 0 , when array is not defined, it is an empty array. Empty array could also be possible when every load_balancer has target_group_arn.
I only need to deny if array is missing or if any of the element in array doesn't have target_group_arn
How should I proceed on this ?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions