Writing Policies for Testing Pulumi Programs
An example that applies PaC-based integration testing to provisioning an AWS EKS cluster.
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set testing-pac-tscd pulumi-examples/testing-pac-tsAn example of writing tests based on Policy as Code (“CrossGuard”) with both infrastructure definition and tests written in TypeScript.
Prerequisites#
- Ensure you have the latest Node.js and NPM.
- Install Pulumi.
- Configure Pulumi to Use AWS (if your AWS CLI is configured, no further changes are required).
Running the tests#
The tests will run while Pulumi deploys the code, right before the deployment of each resource.
-
Restore NPM dependencies:
$ npm install -
Create a new stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init -
Set the AWS region for this program:
Terminal window pulumi config set aws:region us-west-2 -
Run
pulumi upwithtestsfolder as policy:$ pulumi up --policy-pack testsThe preview displays that Policy Pack will run:
Policy Packs run:Name Versiontests-pack (tests) (local)Confirm the preview with
yesand watch the deployment happen with tests running in parallel. If a test fails, the deployment will stop. -
Tear down your stack’s resources by destroying and removing it:
Terminal window pulumi destroy --yespulumi stack rm --yes
Further steps#
Learn more about testing Pulumi programs: