Pulumi Automation API Stack Not Found
In this tutorial, you'll learn about Pulumi Automation API Stack Not Found. We cover key concepts, practical examples, and best practices.
The Pulumi Automation API throws 'stack not found' errors even after the stack is created.
Wrong ❌
// Wrong: using a stack without creating or selecting it first
import { LocalWorkspace } from "@pulumi/pulumi/automation";
async function deploy() {
const workspace = await LocalWorkspace.create({});
const stack = await workspace.selectStack("dev"); // Stack does not exist
await stack.up();
}
Wrong Output
Error: stack 'dev' does not exist
at LocalWorkspace.selectStack (automation/index.js:...)
Available stacks: []
Right ✅
import { LocalWorkspace } from "@pulumi/pulumi/automation";
async function deploy() {
const workspace = await LocalWorkspace.create({
projectSettings: {
name: "my-project",
runtime: "nodejs",
},
program: async () => {
const bucket = new aws.s3.Bucket("my-bucket");
return { bucketName: bucket.bucketName };
},
});
// Create or select the stack
const stack = await workspace.createStack("dev");
// Or: const stack = await workspace.selectStack("dev");
// Configure the stack
await stack.setConfig("aws:region", { value: "us-east-1" });
// Deploy
const result = await stack.up({ onOutput: console.log });
console.log(`Deploy complete: ${result.outputs.bucketName.value}`);
}
Right Output
Deploying stack 'dev'...
+ aws:s3:Bucket "my-bucket" created
Deploy complete: my-bucket-abc123
Prevention
- Use createStack() for new stacks, selectStack() only for existing stacks.
- Initialize LocalWorkspace with projectSettings when no Pulumi.yaml exists.
- Set required configuration values (like aws:region) before calling stack.up().
- Handle the StackAlreadyExists error when createStack is called on an existing stack.
- Use onOutput callback to stream deployment logs in real-time.
DodaTech applies similar defensive patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro infrastructure for production reliability.
Common Mistakes with automation api
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
These mistakes appear frequently in real-world PULUMI code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
This quick fix is part of the DodaTech infrastructure engineering series. Learn more at DodaTech tutorials.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro