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.
error: could not create stack: stack 'dev' already existsCommon 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
- Replace unconditional
stack initwith a select that creates on miss. - Use
stack select --createso existing stacks are reused. - Re-run the pipeline.
pulumi stack select dev --createLet the Pulumi action manage the stack
The official action selects (and can create) the stack for you, avoiding a bare init that collides.
- uses: pulumi/actions@v6
with:
command: up
stack-name: devHow to prevent it
- Use
stack select --createinstead of unconditionalstack init. - Keep stack creation idempotent so replays do not fail.
- Avoid creating stacks manually that a pipeline also initializes.