Skip to content

Triggering Dependent Stack Updates ​

When you split your infrastructure across multiple stacks, an upstream stack often exposes outputs that downstream stacks consume through a stack reference — for example, a network stack whose VPC ID feeds a database stack, which in turn feeds a compute stack. A stack reference reads the current outputs of the upstream stack, but it does not re-run the downstream stack on its own. When the upstream stack changes, you need a way to cascade an update to the stacks that depend on it.

The supported way to do this is with Pulumi Deployments: configure the downstream stack to run automatically when the upstream stack's update succeeds. This page covers the recommended pattern, how to keep it from firing duplicate or looping deployments, and why to avoid rolling your own webhook.

Trigger each downstream stack from the upstream stack's update_succeeded event, using a deployment webhook destination for each upstream → downstream edge.

If you'd rather update a set of dependent stacks together, in order, as one release, use Pulumi Delivery. A Delivery Stacks resource orders stack updates by their stack references, so you don't wire up a webhook per edge.

These dependencies usually follow one of two patterns:

  • Layered infrastructure within an environment: stacks in the same environment build on one another — a network stack feeds a database stack and a cluster stack, which in turn feed an app stack. Updating a lower layer cascades to the layers above it.
  • Promoting a change across environments: the same layer flows from one environment to the next — updating network/dev promotes to network/staging, which promotes to network/prod.

Both patterns are directed acyclic graphs.

Every stack you want to deploy automatically must be configured with deployment settings, since the trigger runs the target stack through Pulumi Deployments.

The user or token that creates a deployment webhook must be allowed to deploy its target stack, which takes the stack_deployment:create scope (granted by the Stack Write permission set). When you manage webhooks with Pulumi IaC, that is the identity running pulumi up on the orchestration stack, so give it Stack Write on every downstream stack. See Required permissions for the full list of checks.

The examples on this page use the Pulumi Service provider and Pulumi IaC to manage these webhooks declaratively, which is the recommended approach — your dependency wiring lives in code, is reviewed, and stays in sync with the rest of your infrastructure. You can also configure the same webhooks through the Pulumi Cloud console or the REST API if you prefer.

WARNING

Manage the webhooks and deployment settings in a separate stack from the infrastructure they orchestrate. The orchestration wiring and the infrastructure have different lifecycles — you don't want a change to (or a pulumi destroy of) your application infrastructure to also tear down the webhooks that keep your dependent stacks up to date, and vice versa.

Deployment webhook destinations ​

A deployment webhook destination lets you pick one or more event types on a stack (for example, update_succeeded) and deliver the event to a destination — in this case, the Create Deployment API of another stack. In the example below, an update to the network stack triggers the database stack, and an update to the database stack triggers the compute stack.

typescript
import * as pulumi from "@pulumi/pulumi";
import * as pulumiservice from "@pulumi/pulumiservice";

const databaseWebhook = new pulumiservice.Webhook("databaseWebhook", {
    organizationName: "org",
    projectName: "network",
    stackName: "prod",
    format: pulumiservice.WebhookFormat.PulumiDeployments,
    payloadUrl: "database/prod",
    active: true,
    displayName: "deploy-database",
    filters: [pulumiservice.WebhookFilters.UpdateSucceeded],
});
const computeWebhook = new pulumiservice.Webhook("computeWebhook", {
    organizationName: "org",
    projectName: "database",
    stackName: "prod",
    format: pulumiservice.WebhookFormat.PulumiDeployments,
    payloadUrl: "compute/prod",
    active: true,
    displayName: "deploy-compute",
    filters: [pulumiservice.WebhookFilters.UpdateSucceeded],
});

Avoiding duplicate fires and re-trigger loops ​

The most common problems people hit when cascading deployments are the same stack deploying several times for a single upstream change, or two stacks re-triggering each other indefinitely. The supported pattern avoids both when you follow these rules:

  • Filter on a single terminal event. Trigger on update_succeeded only. A single deployment emits several events over its lifecycle — deployment_queued, deployment_started, and finally update_succeeded — so subscribing to more than one event kind (or to lifecycle events instead of the terminal one) causes the downstream stack to fire multiple times per upstream change.
  • Target the downstream stack's deployment directly. Use the built-in Deployment webhook destination, which calls the Create Deployment API of a specific stack. This is a directed edge with a known endpoint, unlike a generic HTTP webhook pointed at custom automation that runs pulumi up and can fan out to more work than you intended.
  • Keep the dependency graph acyclic. Never let stack A trigger stack B while stack B triggers stack A, whether directly or through a longer chain. A cycle means each update triggers the next one forever. Model your stacks as a directed acyclic graph (DAG).

What to avoid: the naive webhook workaround ​

A tempting shortcut is to attach a generic webhook to the upstream stack that points at a custom endpoint — a serverless function or a CI job — which then shells out to pulumi up on the downstream stack. Avoid this. In practice it tends to:

  • Fire far more often than intended, because a generic webhook that isn't narrowly filtered receives every event kind for the stack, so one upstream change can kick off many downstream runs.
  • Re-trigger in loops, because custom automation has no built-in awareness of the dependency graph and nothing stops a downstream update from triggering the upstream one again.
  • Duplicate deployment logic outside Pulumi, reimplementing credentials, source configuration, and settings that deployment settings already manage.

Use a deployment webhook destination instead. It runs the target stack through Pulumi Deployments with its saved settings, so the trigger stays scoped to one deployment per upstream change.

Triggering with custom or one-off settings ​

A deployment webhook runs the target stack with its existing deployment settings and cannot override them. When you need to trigger a downstream deployment with custom or one-off settings — a different branch, environment variables, or pre-run commands — use the REST API trigger instead, which accepts settings in the request body.

Content from the official Pulumi documentation (github.com/pulumi/docs).