hi, I'm wondering why the StackReference getOutput...
# general
hi, I'm wondering why the StackReference getOutput returns with an Output type? Is it possible that it returns an unresolved output or the other stack is running and it will return the latest output when the referenced stack deploy finished?
I think the primary reason is that the name of the target stack is an
, so could be something you compute as part of an output of another resource. This is certainly not the most common case though.
thanks, but this could make coding more complex, now I tried a quick hack:
Copy code
import * as pulumi from '@pulumi/pulumi'

async function run() {
  const mainStackRef = new pulumi.StackReference(`stackRef-main`, {
    name: `mainStack`
  const fixedIpSubnetIds: pulumi.Output<string[]> = mainStackRef.getOutput('fixedIpSubnetIds')

  const fixedIps: string[] = await new Promise((resolve, reject) => {
    fixedIpSubnetIds.apply(t => resolve(t))


It logs the ips, even during pulumi preview, I assume because that Output value already known. Can we rely on this behavior or this is not guaranteed?
FWIW - I think you can accomplish the same with just:
Copy code
fixedIpSubnetIds.apply(t => console.log(t))
I'm not positive you can also rely on the code as you wrote it - for example, during previews - though I expect that you can. Is your real use case more complex than
? I'd be interested to see more of it to understand how you want to use the value from the
Yes, it's more complex, it's just a small example, this connects to an earlier conversation: https://pulumi-community.slack.com/archives/C84L4E3N1/p1551129344303800
You said,
is a case, when we need to create resources in apply, I thought we could avoid that(based on this example), so the main idea is to get the
values with this trick and create resources looping through that, this way we could see the resource changes during preview too
It works during previews, we just don't know, that we can rely on that or not.
https://github.com/pulumi/pulumi/blob/master/sdk/nodejs/output.ts#L212 based on this it works because the stack output already is known when the output created, so it works during preview too
but still curious that we can rely on this or not 🙂