files or input_schema publishes a new version, and the apply waits until Kosli has validated it.
Deleting this resource archives the policy in Kosli rather than hard-deleting it: the policy leaves the policy list, while its versions stay readable and an evaluation by its identifier still runs. Creating the resource again with the same
identifier publishes to the archived policy and unarchives it.Example usage
Versions and validation
Kosli stores a policy as a series of immutable versions. Publishing returns a version in statuspending, and Kosli validates it asynchronously:
Only a change to
files or input_schema creates a new version. A change to name or description updates the policy in place, and a change to comment alone publishes nothing. Every update sends the whole bundle again, because Kosli has one publish call for both the files and the metadata.
version shows as known after apply on every update. Kosli never reuses a rejected or failed version, so publishing the current files again can still store a new version.
The resource tracks the policy’s current version: the highest-numbered valid version, which is the one an evaluation runs. After an apply that ends with a rejected version, the policy keeps running its previous valid version and the next plan still shows the pending change.
A version published outside Terraform shows up as a change to files on the next plan, once it is valid.
Destroying
Kosli never hard-deletes a Rego policy.terraform destroy, or removing a kosli_rego_policy from the configuration, archives the policy:
- It leaves the default policy list in Kosli.
- Its versions, files and past evaluations stay readable.
- An evaluation by its identifier still runs.
- Its identifier stays taken.
kosli_rego_policy with the identifier of an archived policy publishes to that policy and unarchives it, so the version numbers continue from where they stopped.
A policy whose first version is rejected, or is still pending at the timeout, exists in Kosli but is not in the Terraform state. Applying again publishes to it. If you remove the resource from the configuration instead, the policy stays in Kosli and you have to archive it there.
A policy archived outside Terraform reads as deleted: the next plan proposes to create it, and the apply unarchives it.
Import
Rego policies can be imported using their identifier:comment is not read back from Kosli. You can’t import an archived policy; unarchive it in Kosli first.
Querying Rego policies
To read a policy’s current version or a specific version, including its files and digest, use thekosli_rego_policy data source.
Schema
Required
files(Map of String) The Rego bundle, as a map of each file’s relative path to its source. A single-file policy is one entry. Kosli limits a bundle to 100 files and 1 MiB in total, and rejects paths that leave the bundle.identifier(String) Unique identifier of the policy within the organization. Must start with a letter or number and contain only letters, numbers, periods (.), hyphens (-), underscores (_), and tildes (~). Kosli compares identifiers without regard to case. Changing this to a different policy will force recreation of the resource.input_schema(String) Shape of the input the policy is written against. Known values:trail(the policy evaluates one trail) andtrails(a set of trails). The Kosli API validates the value.name(String) Human-readable display name of the policy. Can be changed without publishing a new version.
Optional
comment(String) Why this version is published. Kosli stores the comment with the version an apply creates; changing only the comment publishes nothing, and the value is not read back from Kosli.description(String) Free-form description of the policy. Can be changed without publishing a new version.
Read-only
created_at(String) RFC3339 UTC timestamp of when the policy was created.created_by(String) Display name of the user who created the policy.digest(String) Digest of the current version’s files, assha256:and a hex digest. A decision made with the policy cites this value.entrypoint(String) Policy package Kosli found as the entrypoint of the current version.params_schema(String) JSON Schema, as a JSON string, that the current version declares for its params. Null when the policy declares none.version(Number) Number of the policy’s current version: the highest-numbered valid version, which is the one an evaluation runs.