Hi, I’m using typescript and I want to run 2 stack...
# getting-started
Hi, I’m using typescript and I want to run 2 stacks in a row. I would like the second stack to be initialized with an output from the first stack. Is it possible using the automation api ? can you give a sample code ?
Yes, the Automation API can definitely do that! Here is how to orchestrate this:
Copy code
import { LocalProgramArgs, LocalWorkspace } from "@pulumi/pulumi/automation";
const stack1 = await LocalWorkspace.selectStack({workDir: '/path/to/project1', stackName: 'foo'});
await stack1.up();
const stack2 = await LocalWorkspace.selectStack({workDir: '/path/to/project2', stackName: 'bar'});
await stack2.up();
The only missing piece here is to make the project2/bar stack to consume outputs from the project1/foo stack.
thanks. can you please explain how stack2 consume the outputs ? 🙂
1. Export data from project1 (outputs) 2. In prject2 use a stack reference to consume those outputs https://www.pulumi.com/learn/building-with-pulumi/stack-outputs/ https://www.pulumi.com/learn/building-with-pulumi/stack-references/
Thanks 🙂 what I’m looking for is to inject somehow the output of stack1 into stack2 using automation api. what you showed here is using stackRef (part of sdk) - which is great and working but not what I’m looking for.. I asking if there away to do something like this:
Copy code
const stack1 = await LocalWorkspace.selectStack(args1)

const upRes1: UpResult = await stack1.up({})
const stack1outputs = upRes1.outputs
const stack2 = await LocalWorkspace.selectStack(args2, stack1outputs) // here 
const upRes2: UpResult = await stack2.up(stack1outputs) // or here
according to documentation it’s not an option But I’m asking if there is a workaround in order to achieve that ? I found this example in go https://github.com/pulumi/automation-api-examples/blob/main/go/multi_stack_orchestration/main.go looking for something similar in typescript Thanks!
I'd try something like:
Copy code
const stack1 = await LocalWorkspace.createOrSelectStack(stack1args);
const stack2 = await LocalWorkspace.createOrSelectStack(stack2args);
await stack2.setConfig("stack2:some-key", { value: stack1.outputs.outputName.value });
await stack2.up();
(disclaimer: did not try - i only used the automation api in python so far)
this approach expects: • stack1 to export "outputName" • stack2 to use a config key named "some-key"
when running stack2.up() it run the
of that project. how can I access the
inside that file ?
From the 2nd project's perspective, it's a simple configuration value:
Copy code
const config = new Config();
const value = config.require('some-key');
Thanks @clever-painter-96148 I think your advice could be good approach to handle my situation. Do you think it’s the best practice ? I mean where exactly those config located ? on my local dick ? Does those values will be written into pulumi.<stackname>.yaml file ? Thanks.
Do you think it’s the best practice ?
Not sure, I started using the Automation API a few days ago. 😅 Maybe @many-telephone-49025, @billowy-army-68599 or @limited-rainbow-51650 can help?
I mean where exactly those config located ?
Yes, configuration done with the Automation API gets written on your local filesysteme in
what if I have big outputs to forward to next stacks ? what are the limitations ?
It's a configuration API. I am not sure about the exact limitations but I'd avoid passed big payload there.
Hi @many-telephone-49025, @billowy-army-68599 @limited-rainbow-51650 If possible, I would like to hear what is your suggestion here, what is the best practice to pass outputs between micro stacks using
The only way to do this is via stack references. You can’t pass outputs between stacks even inline automation API programs
@billowy-army-68599 what about that example in go ?
I’m on mobile at the moment, which part are you referring to?
Ah, in that case you’ve got an exported output which is resolved (so it’s now a string) and you’re passing it as a standard string to another program, essentially like configuration. That is functionally the same mechanism as a stack reference, in that the output is resolved when the program completes. It’s just another way of reading the value into the program