Use the Pulumi Automation API to build a CI script that provisions ephemeral preview environments per pull request and tears them down on merge

domain: Pulumi · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Write a Node.js or Python script that imports the Pulumi Automation API and constructs a LocalWorkspace pointing to the Pulumi program directory; use stack.create or LocalWorkspace.createOrSelectStack with the PR number as the stack name suffix
  2. Call stack.setConfig in the script to inject per-PR values such as subdomain prefix, feature flags, and the source branch; these configs propagate into the Pulumi program as config.require calls
  3. Run stack.up({ onOutput: console.info }) and capture the stack outputs including the preview URL; post the URL as a pull request comment using the GitHub REST API from within the same script
  4. On the merge event, run the same script with stack.destroy followed by stack.workspace.removeStack to fully clean up the stack and its state from the Pulumi backend
  5. Wrap the up and destroy calls in try-catch blocks and emit structured logs; on failure, post a comment to the PR with the last 50 lines of output captured from the onOutput stream
  6. Use a Pulumi Stack Reference in a shared monitoring stack that reads the preview environment outputs so alerts and dashboards automatically discover ephemeral stacks

Known gotchas

Related routes

Use the Pulumi Automation API in Python to programmatically create and destroy ephemeral stacks with inline programs for integration test environments
pulumi.com · 5 steps · unrated
Provision ephemeral namespace-per-PR environments using GitHub Actions and kubectl
docs.github.com/actions · 6 steps · unrated
Configure an Argo CD ApplicationSet using the Pull Request generator to create a preview Application per open pull request in a GitHub repository
Argo CD · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans