https://pulumi.com logo
Title
b

bitter-psychiatrist-55958

04/07/2022, 8:27 AM
is there an automation api to list all stacks for a project?
l

limited-rainbow-51650

04/07/2022, 8:49 AM
Not an automation API, but if you are using the Pulumi hosted service as your state backend, you can use their official API: https://www.pulumi.com/docs/reference/service-rest-api/#list-stacks
b

bitter-psychiatrist-55958

04/07/2022, 8:51 AM
aww bummer. alright. no im not using that. guess I can shell out for that for now.
l

limited-rainbow-51650

04/07/2022, 9:09 AM
Why shell out? With Pulumi, you are using code, which means you can use any http library to perform requests against that API.
👍 1
b

bitter-psychiatrist-55958

04/07/2022, 9:13 AM
Because I'm not using the pulumi service?
l

limited-rainbow-51650

04/07/2022, 9:22 AM
Sorry, overlooked that in your previous answer.
🙏 1
Which state backend are you using? And which programming language are you using for Pulumi code?
b

bitter-psychiatrist-55958

04/07/2022, 9:48 AM
S3 and TypeScript.
The
-j
flag makes parsing simple fwiw.
l

limited-rainbow-51650

04/07/2022, 9:57 AM
In your setup, I still would not shell out, but go for a coding approach in which you use the
aws-sdk
library to iterate over the s3 folders in your state bucket: https://www.npmjs.com/package/aws-sdk
b

bored-oyster-3147

04/07/2022, 2:49 PM
Am I being a dummy and misunderstanding the question or does Automation API actually support this? https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/automation/#Workspace-listStacks
👀 1
g

green-musician-49057

04/07/2022, 4:39 PM
b

bitter-psychiatrist-55958

04/07/2022, 6:00 PM
@bored-oyster-3147 nice yeah! Very funny to see the actual implementation is exactly how I did it xD
Im unsure how to use that call though. Doesn't seem to be available on
LocalWorkspace
anyways. I am using it like this atm:
const stack = await LocalWorkspace.createOrSelectStack(args);
b

bored-oyster-3147

04/07/2022, 6:03 PM
It is not a static function it is an instance function. You must first instantiate a workspace instance
Your example is like a helper function to bypass creating a workspace instance and get a stack instance in one line, but you could either access the workspace with stack.Workspace after doing that or not instantiate a stack and simply instantiate a workspace instead