is there an automation api to list all stacks for ...
# automation-api
b
is there an automation api to list all stacks for a project?
l
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
aww bummer. alright. no im not using that. guess I can shell out for that for now.
l
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
Because I'm not using the pulumi service?
l
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
S3 and TypeScript.
The
-j
flag makes parsing simple fwiw.
l
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
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
b
@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:
Copy code
const stack = await LocalWorkspace.createOrSelectStack(args);
b
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
257 Views