terraform plan shows exactly what will change, and a dry run can stop a broken or noisy policy before it reaches your tenant. The provider works with Terraform 1.5 or later.
Before you start
You need a tenant API key. See API keys to create one. The key’s role must include these permissions:
You also need the API address of your region. API keys only work in the region where they were created.
Steps to create a custom check
1
Configure the provider
Add the provider to your configuration and set the API address for your region.Set the API key with the
PLERION_API_KEY environment variable rather than writing it in a file.2
Write the policy
Save the Rego policy in its own file, for example See What a policy receives and returns for the full contract.
policies/github-oidc-roles.rego. This policy reports every IAM role that GitHub Actions can assume from any repository.3
Add the check
slugmust be unique in the tenant. You can rename it later without replacing the check.scope = "batch"evaluates the assets in chunks, which suits checks that look at one asset at a time.scope = "all"evaluates every asset of the type together, for checks that compare assets with each other.defaultsapplies to every finding unless the policy’s result sets a value itself.
4
Apply the change
- Run
terraform initto download the provider. - Run
terraform planto review the change. - Run
terraform applyto create the check.
Preview findings before you apply
Theplerion_custom_check_dry_run data source runs a policy against one integration and returns the findings it would produce, without saving them. Terraform reads it during the plan, and the read fails if the policy cannot be evaluated, so a broken policy stops the plan.
To check a change before it reaches your tenant, keep the check’s settings in locals and give the same values to the check and to the dry run. A precondition on the check then stops the apply when the preview isn’t what you expect.
Bring existing checks under Terraform
Checks created in the Plerion app or through the API can be imported by their slug or their ID.1
Add an import block
2
Generate the configuration
Run
terraform plan -generate-config-out=generated.tf. Terraform reads the check and writes a matching plerion_custom_check block to generated.tf. Terraform marks this option as experimental, so review the file before you keep it.3
Apply the import
Run
terraform apply. The plan should show one import and no changes. Move the policy into its own file if you like, then remove the import block.What a policy receives and returns
A policy must declarepackage custom and define a rule named result. Plerion evaluates the rule and reads its value as a list of verdicts.
The policy receives:
Each verdict in
result is an object:
Every verdict becomes a finding, so an asset left out of
result has no finding. If any verdict has another status, or names an asset that isn’t in input.assets, Plerion rejects the whole evaluation.
The provider documentation lists every attribute of the resource and data sources. For one-off tasks from a terminal, see the plerion custom-checks CLI commands.