Hi, I’m trying to list all stacks from an organiza...
# automation-api
Hi, I’m trying to list all stacks from an organization and encountered the following error, any suggestions?
Copy code
Test stack List
Error retrieving stacks: Error: Failed to get Pulumi CLI
    at get pulumiCommand [as pulumiCommand] (/node_modules/@pulumi/pulumi/automation/localWorkspace.js:110:19)
    at LocalWorkspace.<anonymous> (/node_modules/@pulumi/pulumi/automation/localWorkspace.js:808:25)
    at Generator.next (<anonymous>)
    at /node_modules/@pulumi/pulumi/automation/localWorkspace.js:21:71
    at new Promise (<anonymous>)
    at __awaiter (/node_modules/@pulumi/pulumi/automation/localWorkspace.js:17:12)
    at LocalWorkspace.runPulumiCmd (/node_modules/@pulumi/pulumi/automation/localWorkspace.js:799:16)
    at LocalWorkspace.<anonymous> (/node_modules/@pulumi/pulumi/automation/localWorkspace.js:643:39)
    at Generator.next (<anonymous>)
The code looks like this:
Copy code
import {
} from "@pulumi/pulumi/automation/index.js";

// Function to retrieve all stacks in a given organization
const listAllStacksInOrg = async (organizationName) => {
    try {
        // Set the Pulumi organization context
        const org = organizationName;

        // Create a Pulumi Service (backend) client
        const pulumiServiceClient = new LocalWorkspace();

        // List all stacks in the specified organization
        const stacks = await pulumiServiceClient.listStacks();

        // Filter stacks by organization name
        const orgStacks = stacks.filter(stack => stack.organization === org);

        // Return the list of stack names
        return orgStacks.map(stack => stack.name);
    } catch (error) {
        console.error("Error retrieving stacks:", error);
        throw error;

export {
Pulumi is installed by homebrew and runs OK from CLI.
Copy code
$ which pulumi