Modern QA2026Integration Testing with Pulumi Automation API — tiles
Log inJoin
9 / 75 · 08 Infrastructure as Code Testing · Pulumi Testing← prev⊞ allnext →☰ Read as one page

2.4Integration Testing with Pulumi Automation API

The Pulumi Automation API allows you to drive Pulumi from within test code, similar to how Terratest drives Terraform:

// tests/integration/s3-bucket.test.ts
import { LocalWorkspace, Stack } from "@pulumi/pulumi/automation";
import { S3Client, GetBucketEncryptionCommand } from "@aws-sdk/client-s3";
import { describe, it, expect, afterAll } from "vitest";

describe("S3 Data Bucket Integration Test", () => {
    let stack: Stack;
    let bucketName: string;

    it("deploys and validates the bucket", async () => {
        // Create a stack using inline Pulumi program
        stack = await LocalWorkspace.createOrSelectStack({
            stackName: "test-integration",
            projectName: "s3-test",
            program: async () => {
                const aws = await import("@pulumi/aws");
                const bucket = new aws.s3.Bucket("test-data-bucket", {
                    serverSideEncryptionConfiguration: {
                        rule: {
                            applyServerSideEncryptionByDefault: {
                                sseAlgorithm: "aws:kms",
                            },
                        },
                    },
                    versioning: { enabled: true },
                });
                return { bucketName: bucket.bucket };
            },
        });

        // Deploy real infrastructure
        const upResult = await stack.up({ onOutput: console.log });
        bucketName = upResult.outputs.bucketName.value;

        // Verify with AWS SDK
        const s3 = new S3Client({ region: "us-east-1" });
        const encryption = await s3.send(
            new GetBucketEncryptionCommand({ Bucket: bucketName })
        );

        expect(
            encryption.ServerSideEncryptionConfiguration?.Rules?.[0]
                ?.ApplyServerSideEncryptionByDefault?.SSEAlgorithm
        ).toBe("aws:kms");
    }, 120_000); // 2-minute timeout for real infra

    afterAll(async () => {
        if (stack) {
            await stack.destroy({ onOutput: console.log });
            await stack.workspace.removeStack("test-integration");
        }
    });
});