Skip to content

Commit

Permalink
docs: add hint about prepended variable definitions for the policies
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrom089 committed Jan 24, 2025
1 parent 3133cee commit 716160b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/concepts/policy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,39 @@ This takes you to the policy creation screen where you can choose the type of po

Once you're done, click on the _Create policy_ button to save it. Don't worry, policy body is mutable so you'll always be able to edit it if need be.

### Policy structure

We prepend variable definitions to each policy. These variables can be different for each type, but the prepended code is very similar. Here's an example for the [Approval](approval-policy.md) policy:

```opa
package spacelift
# This is what Spacelift will query for when evaluating policies.
result = {
"approve": approve,
"reject": reject,
"flag": flag,
"sample": sample,
}
# Default to ensure that "approve" is defined.
default approve = false
# Default to ensure that "reject" is defined.
default reject = false
# Default to ensure that "sample" is defined.
default sample = false
# Placeholder to ensure that "flag" will be a set.
flag["never"] {
false
}
```

!!! warning
Remember that you can't change predefined variable types. Doing so will result in a policy validation error and the policy won't be saved.

## Attaching policies

### Automatically
Expand Down

0 comments on commit 716160b

Please sign in to comment.