https://pulumi.com logo
Title
l

lively-crayon-44649

11/09/2022, 11:04 AM
Is there a way to get the outputs of another stack in the automation API, using only
org/project/stack
? So basically a
StackReference
but outside Pulumi? My use case is I want to load the outputs of another stack, without having to know its relative path in my monorepo, before doing some setup (SSH tunnel) and then running another stack, all using Pulumi Automation. If that makes sense.
m

millions-furniture-75402

11/09/2022, 1:37 PM
Pulumi automation api is a wrapper for the pulumi CLI. If you can do it with the CLI directly, you can likely achieve it with the automation api.
pulumi stack init org/project-1/sandbox
pulumi stack select org/project-1/sandbox
pulumi up
pulumi stack output
https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/automation/#Workspace-stackOutputs
l

lively-crayon-44649

11/09/2022, 2:29 PM
Thanks @millions-furniture-75402! At present it seems like I have to
select
using
LocalWorkspace
, which wants a path (and I can work around), but I'll dig into the API code and see if there's something more direct.
m

millions-furniture-75402

11/09/2022, 2:33 PM
Here's some older code that might be a useful reference
export class Gameserver {
  public createStack = async (gameserverStackName: string, configMap: ConfigMap): Promise<any> => {
    return await this.updateStack(gameserverStackName, configMap);
  }

  public destroyStack = async (gameserverStackName: string): Promise<any> => {
    const stack = await this.selectStack(gameserverStackName);
    const response = await stack.destroy({ onOutput: <http://console.info|console.info> });
    await stack.workspace.removeStack(stack.name);
    return response;
  }

  public redeployStack = async (gameserverStackName: string, configMap: ConfigMap): Promise<any> => {
    const stack = await this.selectStack(gameserverStackName);
    await stack.destroy({ onOutput: <http://console.info|console.info> });
    return await this.updateStack(gameserverStackName, configMap);
  };

  public updateStack = async (gameserverStackName: string, configMap?: ConfigMap): Promise<any> => {
    const stack = await this.selectStack(gameserverStackName);

    if (configMap) {
      await stack.setAllConfig(configMap);
    }

    return await stack.up({ onOutput: <http://console.info|console.info> });
  };

  public selectStack = async (gameserverStackName: string): Promise<any> => {
    <http://console.info|console.info>(gameserverStackName);
    const args: LocalProgramArgs = {
      stackName: gameserverStackName,
      workDir: upath.joinSafe(__dirname, ".."),
    };

    return await LocalWorkspace.createOrSelectStack(args);
  };
}
That was written for the original beta version of the automation API, but it should be largely the same, and help clarify the orchestration.
l

lively-crayon-44649

11/09/2022, 2:52 PM
Yea I'm trying to avoid that
workDir
basically but it's not a dealbreaker
m

millions-furniture-75402

11/09/2022, 2:54 PM
The automation api is tightly coupled with the pulumi cli. Another gotcha is the tight coupling with stack config. It will be manipulating stack YAML files on disk.
l

lively-crayon-44649

11/09/2022, 3:04 PM
Yea, makes sense. It's OK -- I can live with the workspace directories. Thanks again for the help and replies! 🙂