Manage policies as code with Terraform

Cloudsmith's Terraform provider (v0.0.75) now supports full lifecycle management of policies and policy actions as code.

We’ve added native Terraform resources and data sources that let you create, configure, and manage policies as code, including Rego rules and associated actions, directly from your infrastructure-as-code workflows.

How it works

Four new Terraform constructs are available:

  • cloudsmith_policy: Defines a workspace-scoped policy with a Rego rule, precedence, enabled state, and whether it is terminal in the evaluation chain.
  • cloudsmith_policy_action: Attaches one or more actions to a policy (e.g. quarantine a package, add/remove tags, hide a package), each with its own precedence.
  • data.cloudsmith_policy: Returns a specific policy by its slug for use as a reference or output.
  • data.cloudsmith_policy_list: Queries multiple policies by name pattern or sort order.

See the policy example in the terraform-provider-cloudsmith GitHub repository for an example of a Terraform module that uses the Cloudsmith provider to create:

  • A quarantine-on-missing-tag policy
  • A tag cleanup policy
  • A cooldown policy

To learn more, see the Terraform Registry: Cloudsmith documentation.

Getting started

Policy as code is currently available in early access. If you would like to try this feature, please contact us.


Keep up to date with our monthly product bulletin