Policy API & SDK Reference
Pulumi provides SDKs for authoring policy packs in TypeScript/JavaScript and Python, 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.
| Language | Package | Status |
|---|---|---|
| TypeScript/JavaScript | @pulumi/policy | Stable |
| Python | pulumi_policy | Stable |
Getting started with the SDK
Create a new policy pack project with the CLI:
pulumi policy new aws-typescript
A basic policy pack looks like this:
import { PolicyPack, validateResourceOfType } from "@pulumi/policy";
import * as aws from "@pulumi/aws";
new PolicyPack("my-policies", {
policies: [
{
name: "s3-no-public-read",
description: "Prohibits setting the publicRead ACL on S3 buckets.",
enforcementLevel: "mandatory",
validateResource: validateResourceOfType(aws.s3.Bucket, (bucket, args, reportViolation) => {
if (bucket.acl === "public-read") {
reportViolation("S3 buckets must not have the publicRead ACL.");
}
}),
},
],
});
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.
Pulumi Service Provider
The Pulumi Cloud (pulumiservice) provider includes resources and functions for managing policies programmatically as part of your Pulumi infrastructure code.
Resources
| Resource | Description |
|---|---|
PolicyGroup | Apply policy packs to a set of stacks or cloud accounts in your organization. Supports audit and preventative enforcement modes. |
Functions
| Function | Description |
|---|---|
getPolicyPack | Get details about a specific version of a policy pack, including its configuration and policies. |
getPolicyPacks | List all policy packs for an organization. |
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.