Skip to content

Policy API and SDK reference ​

Pulumi provides SDKs for authoring policy packs in TypeScript/JavaScript and Python, plus support for OPA (Rego), and REST API endpoints for managing policies programmatically through Pulumi Cloud.

Policy SDK ​

The Policy SDK lets you define and validate policies in code. Use it to write custom policy packs that enforce your organization's compliance and security requirements.

LanguagePackageStatus
TypeScript/JavaScript@pulumi/policyStable
Pythonpulumi_policyStable
OPA (Rego)pulumi-policy-opaStable

Getting started with the SDK ​

Create a new policy pack project with the CLI:

bash
pulumi policy new aws-typescript

A basic policy pack looks like this:

typescript
import { PolicyPack, validateResourceOfType } from "@pulumi/policy";
import * as aws from "@pulumi/aws";

new PolicyPack("my-policies", {
    policies: [
        {
            name: "rds-storage-encryption",
            description: "Requires RDS instances to have storage encryption enabled.",
            enforcementLevel: "mandatory",
            validateResource: validateResourceOfType(aws.rds.Instance, (instance, args, reportViolation) => {
                if (!instance.storageEncrypted) {
                    reportViolation("RDS instance must have storage encryption enabled.");
                }
            }),
        },
    ],
});

For a complete guide on writing policies, see write your own policy packs.

Pulumi Cloud REST API ​

The Pulumi Cloud REST API provides endpoints for managing policy packs, policy groups, and policy results programmatically. Use these endpoints to integrate policy management into custom tooling and workflows.

Policy packs ​

Create, list, apply, and delete policy packs in your organization.

Policy groups ​

Manage policy groups that control which policy packs are enforced on which stacks.

Policy results ​

Query policy evaluation results to monitor compliance across your organization.

Stack policy ​

View the policy packs and policy groups associated with a specific stack.

Policy exceptions ​

Create, list, and remove the policy exceptions in your organization.

Pulumi Service Provider ​

The Pulumi Cloud (pulumiservice) provider includes resources and functions for managing policies programmatically as part of your Pulumi infrastructure code.

Resources ​

ResourceDescription
PolicyGroupApply policy packs to a set of stacks or cloud accounts in your organization. Supports audit and preventative enforcement modes.
PolicyPackPublish a policy pack from a local source directory to Pulumi Cloud. Changing the source content publishes a new version.
PolicyGroupStackAttachmentAdd a single stack to a policy group, including a default policy group, without taking ownership of the group.
PolicyGroupInsightsAccountAttachmentAdd a single cloud account to a policy group, including a default policy group, without taking ownership of the group.

Functions ​

FunctionDescription
getPolicyPackGet details about a specific version of a policy pack, including its configuration and policies.
getPolicyPacksList all policy packs for an organization.

Content from the official Pulumi documentation (github.com/pulumi/docs).