https://pulumi.com logo
#general
Title
# general
f

fast-yacht-78432

09/07/2023, 8:00 PM
I'm looking at this documentation: https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/automation/#LocalWorkspace Why is it that the static method
LocalWorkspace.createStack()
returns the promise of a
Stack
whereas if I make an instance of `LocalWorkspace`:
Copy code
const workspace = LocalWorkspace.create({ /* ... */ });
workspace.createStack("somestackname")
here returns
void
? I was going to try a factory that dispensed workpsaces, but I'm wondering if this idea that I produce workspace instances is me misunderstanding the automation api fundamentals. If there is an example of using an instance of a localworkspace as opposed to just that classes static methods for creating at stack and returning information about it I would appreciate it
Copy code
await workspace.createStack(stackName);
			await workspace.selectStack(stackName);
			const stack = await workspace.stack();
I'm able to create a stack, select it, and get a summary about it if it is an instance but I don't see how to effect the state of it to do a stack up or down
f

full-eve-52536

09/07/2023, 8:46 PM
await workspace.stack()
returns a StackSummary type
Whereas something like
const stack = await LocalWorkspace.createOrSelectStack(localProgramArgs, workspaceArgs);
would return a Stack type
f

fast-yacht-78432

09/07/2023, 8:53 PM
@full-eve-52536 thank you for the reply. Are there methods to take an instance of a stack and do an
.up()
with it, or is this only available using the static methods
LocalWorkspace
f

full-eve-52536

09/07/2023, 8:57 PM
I've myself have been only dabbling with the Pulumi automation API. As far as I know, the
up()
method exists on the
Stack
type objects. So something like this should work:
Copy code
const stack = await workspace.selectStack(stackName);
await stack.up();
f

fast-yacht-78432

09/07/2023, 9:00 PM
I think using the static method this would work, but for an instance
.selectStack
returns a
void
with typescript
That's why I'm guessing I'm misunderstanding some sort of design choice
it's like if you have an instance of a workspace the expectation seems to be that you'd
await
all your operations but don't expect a response
f

full-eve-52536

09/07/2023, 9:02 PM
Yeah I found it to be a little strange as well. Ultimately I ended up representing "instances" of
workspace
as
WorkspaceArgs
. I.e:
Copy code
const workspaceArgs: LocalWorkspaceOptions = {
    workDir: infraDir,
    envVars: {
      PULUMI_K8S_ENABLE_PATCH_FORCE: 'true',
      NODE_OPTIONS: '',
    },
  };
f

fast-yacht-78432

09/07/2023, 9:03 PM
I also see there is some option to supply a callback, maybe the idea is I do things more
async
and hit a callback
I like your approach I'll probably do that