|
| 1 | +package terraform.flow_checks |
| 2 | + |
| 3 | +import data.terraform.library |
| 4 | +import rego.v1 |
| 5 | + |
| 6 | +# Retrieve `davinci_flow` resources with a specific action (e.g., "create") |
| 7 | +get_relevant_flows(action) = flows if { |
| 8 | + flows := [flow | |
| 9 | + flow := library.get_resources_by_type_and_action("davinci_flow", action)[_]; |
| 10 | + is_object(flow.change.after) # Ensure `after` is an object |
| 11 | + ] |
| 12 | + # print("Relevant flows retrieved with action:", action, "flows:", flows) # Debugging output |
| 13 | +} |
| 14 | + |
| 15 | +# Check if `deploy` is true for all flows in the input list |
| 16 | +deploy_is_true_for_all(flows) if { |
| 17 | + print("Checking deploy field for each relevant flow.") |
| 18 | + all_true := [flow | |
| 19 | + flow := flows[_]; |
| 20 | + deploy_value := object.get(flow.change.after, "deploy", false) |
| 21 | + # print("Flow deploy value:", deploy_value) # Print the actual deploy value for each flow |
| 22 | + # print("Deploy value is boolean?", is_boolean(deploy_value)) # Debugging output |
| 23 | + deploy_value == true |
| 24 | + ] |
| 25 | + # print("Flows with deploy set to true:", all_true) # Debugging output |
| 26 | + # print("Count of flows with deploy true:", count(all_true)) |
| 27 | + # print("Total number of flows:", count(flows)) |
| 28 | + count(all_true) == count(flows) |
| 29 | + # print("Does count(all_true) == count(flows)?", count(all_true) == count(flows)) # Debugging output |
| 30 | +} |
| 31 | + |
| 32 | +# Check if all flow names start with a given prefix |
| 33 | +name_starts_with_prefix(flows, prefix) if { |
| 34 | + all_prefixed := [flow | |
| 35 | + flow := flows[_]; |
| 36 | + startswith(flow.change.after.name, prefix) |
| 37 | + ] |
| 38 | + # print("Flows with names starting with prefix:", prefix, "flows:", all_prefixed) # Debugging output |
| 39 | + count(all_prefixed) == count(flows) |
| 40 | +} |
0 commit comments