Skip to main content
With the Plerion Terraform provider, you can manage your custom checks as code. Policy changes go through your pull requests, 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 policies/github-oidc-roles.rego. This policy reports every IAM role that GitHub Actions can assume from any repository.
See What a policy receives and returns for the full contract.
3

Add the check

  • slug must 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.
  • defaults applies to every finding unless the policy’s result sets a value itself.
4

Apply the change

  • Run terraform init to download the provider.
  • Run terraform plan to review the change.
  • Run terraform apply to create the check.
Plerion runs the check straight away against your integrations from the matching cloud provider, then again after each scan. Its findings appear alongside your other findings.

Preview findings before you apply

The plerion_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.
Don’t point the dry run at the check’s own attributes, such as plerion_custom_check.github_oidc_roles.body. When the check has changes, Terraform waits until the apply to read the dry run, which is after the check has already changed.
A new dry run starts every time Terraform reads the data source, which is usually on every plan. It evaluates the assets Plerion collected in its most recent scan of the integration.

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 declare package 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.