Skip to content
Latchkey

Pulumi "could not create stack: stack already exists" in CI

A pulumi stack init tried to create a stack the backend already has. Stack names are unique per project in a backend, so re-initializing an existing one fails instead of overwriting it.

What this error means

A step running pulumi stack init <name> fails with "error: could not create stack: stack already exists". Re-running the pipeline reproduces it every time.

pulumi
error: could not create stack: stack 'dev' already exists

Common causes

The pipeline always runs stack init

The workflow unconditionally calls pulumi stack init, which succeeds only the first time and fails on every subsequent run.

The stack was created out of band

Someone created the stack manually or in another pipeline, so a later stack init collides with it.

How to fix it

Select the stack, creating it only if absent

  1. Replace unconditional stack init with a select that creates on miss.
  2. Use stack select --create so existing stacks are reused.
  3. Re-run the pipeline.
Terminal
pulumi stack select dev --create

Let the Pulumi action manage the stack

The official action selects (and can create) the stack for you, avoiding a bare init that collides.

.github/workflows/ci.yml
- uses: pulumi/actions@v6
  with:
    command: up
    stack-name: dev

How to prevent it

  • Use stack select --create instead of unconditional stack init.
  • Keep stack creation idempotent so replays do not fail.
  • Avoid creating stacks manually that a pipeline also initializes.

Frequently asked questions

What causes ""stack already exists""?
The workflow unconditionally calls pulumi stack init, which succeeds only the first time and fails on every subsequent run.
How do I fix "stack already exists"?
Select the stack, creating it only if absent

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card