An example of writing tests based on Policy as Code ("CrossGuard") with both infrastructure definition and tests written in TypeScript.
- 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).
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:
$ pulumi stack init
-
Set the AWS region for this program:
$ pulumi config set aws:region us-west-2
-
Run
pulumi up
withtests
folder as policy:$ pulumi up --policy-pack tests
The preview displays that Policy Pack will run:
Policy Packs run: Name Version tests-pack (tests) (local)
Confirm the preview with
yes
and 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:
$ pulumi destroy --yes $ pulumi stack rm --yes
Learn more about testing Pulumi programs: