Hey gang, is there any way to check the existence ...
# getting-started
Hey gang, is there any way to check the existence of a stack before creating a
new StackReference()
for it? Asking because the error
throws if the stack doesn't exist seems to be uncatchable. This is for Typescript btw, so maybe I should've asked it in #typescript instead 😅
might be a bit hacky, but you could use the pulumi
resource to run
pulumi stack ls
and then you could check in the output of that if the stack exists
Yeah, that was my first hack, but unfortunately it doesn't work with the drift detection we're running in the cloud.
ah, i dont think theres a method for listing stacks programatically - you have to use the command afaik. have you looked at the automation api? that might have something in it you can use
I'll look around some more, thanks for your input 😄
Copy code
The Pulumi Automation API is a programmatic interface for running Pulumi programs without the Pulumi CLI. Conceptually, this can be thought of as encapsulating the functionality of the CLI (pulumi up, pulumi preview, pulumi destroy, pulumi stack init, etc.) but with more flexibility. It is a strongly typed and safe way to use Pulumi in embedded contexts such as web servers without having to shell out to a CLI.
In code, use the Pulumi Service REST API and you can list all stacks, or get a specific stack. Based on the HTTP return code, I think you have what you need: https://www.pulumi.com/docs/reference/service-rest-api/#get-stack
🙏 1