I am trying to write a policy that check if mandatory labels exists.
my sample json looks like this
{
"labels":{
"department":"it_transformation",
"description":"for-sdp-developers",
"environment":"dev",
"owner":"gaurang",
"owner_email":"[email protected]",
"project_code":"111",
"req-num":"xxx-111"
}
}
I want to check it contains owner, owner_email and project_code.
Currently this is what my policy looks like
deny[msg] {
lables_set := {e | e := [_]}
resource := input.resource_changes[_]
not resource.change.after.labels.owner
resource.change.actions[_] != "no-op"
# contains(resource.change.actions, "no-op")
msg := sprintf("New resource '%v' must have a 'owner' label.", [resource.change.after.dataset_id])
}
is there a way I can write some loop, rather than duplicating this block multiple times?