# Post Pulumi Previews on Pull Requests

Yes. An agent adds a workflow that runs pulumi preview on every pull request and posts the diff as a comment, checks it against a local backend, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-preview-comments-to-pr/pulumi/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the Pulumi project before it writes a workflow for it, because the preview has to run the way a developer runs it. In a project like the `aws-ts-s3-folder` example in pulumi/examples, `Pulumi.yaml` names the project, sets `runtime: nodejs` and declares one config value, `aws:region`, with a default of `us-west-2`. `index.ts` creates an `aws.s3.Bucket`, a `BucketWebsiteConfiguration`, a `BucketPublicAccessBlock`, one `BucketObject` per file in `www/` with its MIME type from the `mime` package, and a `BucketPolicy` that `dependsOn` the access block, and exports `bucketName` and `websiteUrl`. `package.json` is `type: module` with `@pulumi/aws` 7.23.0, `@pulumi/pulumi` 3.228.0 and `mime` 4, and `tsconfig.json` compiles `index.ts` alone under `nodenext` with `ts-node` in ESM mode. There is no lockfile and no `Pulumi.<stack>.yaml`, so the stack is created at first use. The examples repository's own `scripts/pr-preview-changed.sh` shows how its maintainers preview a change without cloud credentials: a temporary file backend, a fixed `PULUMI_CONFIG_PASSPHRASE`, and placeholder config seeded for anything missing.

The workflow uses Pulumi's own GitHub Action. The agent adds `.github/workflows/pulumi-preview.yml` on `pull_request` with `contents: read`, `pull-requests: write` and `id-token: write` permissions, checks out the code, sets up Node 22 and runs `npm install` since there is no lockfile to `npm ci` against, then calls `pulumi/actions@v7` with `command: preview`, `stack-name` set to the organization and stack the team deploys, `comment-on-pr: true`, `diff: true` so the comment shows a resource-level diff, and `edit-pr-comment` left at its default of `true`, so each new push updates one comment instead of adding another. `PULUMI_ACCESS_TOKEN` comes from a repository secret, and AWS credentials come from `aws-actions/configure-aws-credentials` with a role assumed through OIDC, which is why the job asks for `id-token: write`; the pull request names the role variable to set and says nothing about the account itself. A second job in the same file, on `push` to the default branch, runs `command: up` with the same inputs, so the comment on the pull request and the deployment after merge come from the same configuration.

A preview against real AWS needs credentials the sandbox does not hold, so the agent proves the workflow the way the maintainers' script does. It installs the Pulumi CLI, runs `pulumi login --local` with a passphrase, `pulumi stack init dev`, `pulumi config set aws:region us-west-2`, sets the AWS provider's `skipCredentialsValidation`, `skipRequestingAccountId` and `skipMetadataApiCheck` options with placeholder access keys, and runs `pulumi preview --diff`. That shows every resource the program creates as an addition, which is the same output the Action will post as a comment, and it runs `npx tsc --noEmit` to be sure the program compiles. The workflow file itself goes through `actionlint`, and the agent reads the Action's `action.yml` to confirm each input name it used exists in the major version it pinned.

The pull request also carries the two things the reviewer has to decide. The stack name in `stack-name` is the team's, and the agent writes it as a placeholder with the `org/stack` form the Action expects for a stack outside an individual account. The backend is the second: a team on Pulumi Cloud needs only the token, while a team on a self-managed backend sets `cloud-url` to its `s3://` bucket and a `PULUMI_CONFIG_PASSPHRASE` secret instead, and the workflow carries both forms with one commented out and a sentence saying which to keep.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a GitHub Actions workflow that runs pulumi preview on every pull request to this Pulumi project and posts the result as a comment. Read Pulumi.yaml, index.ts, package.json, tsconfig.json and any existing workflow first. Use pulumi/actions@v7 with command preview, comment-on-pr true, diff true and the stack name as an org/stack placeholder, with PULUMI_ACCESS_TOKEN from a secret and AWS credentials from aws-actions/configure-aws-credentials through an OIDC role; give the job contents read, pull-requests write and id-token write permissions, and add a second job that runs pulumi up on push to the default branch. Include a commented alternative for a self-managed s3 backend with cloud-url and a passphrase. Prove the program previews cleanly against a local file backend with placeholder AWS settings and skipCredentialsValidation, run npx tsc --noEmit and actionlint on the workflow, and open a pull request quoting the preview output and listing the secrets and variables to set.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request adds `.github/workflows/pulumi-preview.yml` and a short section in the README naming the secrets and variables to set, and changes nothing in the program. Its description quotes the local `pulumi preview --diff` output with the resources the program creates, the clean `tsc` and `actionlint` runs, and lists the three settings the workflow needs: the Pulumi token, the AWS role to assume and the stack name.

A reviewer checks the stack name and the permissions, since `pull-requests: write` is what lets the Action comment and `id-token: write` is what lets the job assume a role, then merges and opens a test pull request to see the first comment land. From then on every pull request carries its own preview, and a push to the same branch edits that comment rather than adding to it.

## Run it on every Pulumi project repository

A platform team hands this off from the terminal once per repository: one `POST /o/{org}/sessions` with this body and the repository in `resources`, naming the project directory in `input` when a repository holds several Pulumi programs. Each run reads its own `Pulumi.yaml`: a Python program gets a `pip install -r requirements.txt` step instead of `npm install`, a project with a lockfile gets `npm ci`, and a project with an existing deploy workflow gets the preview job added to it. A `request_id` that is a UUID v5 of the repository's full name means a retried request returns the run it already started.

The key's `webhook_url` reports each run the key starts with the pull request URL in `result`, so a script that sends one request per repository collects the pull requests without polling.

## Why run it on Rush?

A workflow that previews infrastructure is worth nothing until it runs once, and running it needs a program that compiles, a backend, a stack and the right inputs for the Action's version. The agent installs Pulumi in its own sandbox, previews the program against a local backend the way the project's maintainers do, lints the workflow and reads the Action's inputs from its source, with every command and its output kept in the run's record.

The agent also keeps the secrets where they belong. It never needs the team's cloud credentials to prove the workflow, and the pull request names each secret and variable the reviewer sets rather than asking for them, so the first real preview runs in the team's CI with the team's role.

## Frequently asked questions

### Does the agent need AWS credentials?

No. It previews the program against a local file backend with the AWS provider's credential validation switched off, which shows the same resource diff the Action will post. The real preview on pull requests runs in your CI with the role your workflow assumes through OIDC.

### Will every push add another comment?

No. `pulumi/actions` edits its previous comment by default, through `edit-pr-comment`, so a pull request keeps one comment that always shows the latest preview. Set it to `false` if you want the history of previews kept as separate comments.

### What if we do not use Pulumi Cloud?

The workflow carries a commented block for a self-managed backend: `cloud-url` pointing at an `s3://` bucket and a `PULUMI_CONFIG_PASSPHRASE` secret in place of the access token. The pull request says which block to keep, and nothing else differs.

### Can the same workflow deploy after merge?

Yes. The second job runs `command: up` on push to the default branch with the same stack and credentials, so what the comment showed is what gets applied. Add `expect-no-changes` to the preview job if a pull request that changes nothing should fail instead.

### Does this work for a Python or Go program?

Yes. The Action reads `Pulumi.yaml` for the runtime, and the agent swaps the dependency step for the language it finds, a `pip install` or a `go mod download`. The preview against a local backend works the same way for each.

## More Pulumi jobs

- [Tag Every Resource in a Pulumi Program](https://getrush.ai/run/add-resource-tags/pulumi/)
- [Split a Pulumi Program Into Stacks Linked by StackReference](https://getrush.ai/run/add-stack-references/pulumi/)
- [Protect Databases and Secrets from Accidental Deletion in a Pulumi Program](https://getrush.ai/run/protect-stateful-resources/pulumi/)

## More jobs like this: Hand off a long task

- [Add Private Messaging to a Socket.IO Chat](https://getrush.ai/run/add-private-messaging/socket-io/)
- [Add a Production Override to a Docker Compose Project](https://getrush.ai/run/add-production-compose-override/docker-compose/)
- [Add a Progress Bar to a Go Command-Line Tool](https://getrush.ai/run/add-progress-bar/go-cli/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
