little-cartoon-10569
08/15/2020, 7:59 AMtry {
const stack = new pulumi.StackReference('stackName');
const someId = peerStack.requireOutput("resourceId") as pulumi.Output<string>;
} catch (e) {
if (e instanceof Error) {
pulumi.log.error(e.message);
return pulumi.output(`${e.message}`);
} else {
pulumi.log.error("Unknown object thrown");
return pulumi.output("Unknown error");
}
}
I'm expecting this code to report the error and continue working. But I'm getting
error: Running program '/pulumi/projects/main/pulumi/projects/example' failed with an unhandled exception:
Error: Required output 'someId' does not exist on stack 'stackName'.
at /pulumi/projects/node_modules/@pulumi/pulumi/stackReference.js7223
...And preview fails. Even though I have handled the exception... How can I conditionally skip a section of my code if a required output isn't present in another stack?
requireOutputValue() as pulumi.Input<string>
. No change.ancient-megabyte-79588
08/17/2020, 2:07 PMconst var1 = stackRef.getOutput("someConfigValue") || "default";
you can detect that you didn't get a stack value or adapt in the case it wasn't available with a default value.little-cartoon-10569
08/17/2020, 7:37 PMFetches the value of the named stack output, or throws an error if the output was not found.
Fetches the value promptly of the named stack output. Throws an error if the stack output is not found.
The stack doesn't have the object I'm requesting (there is no export
for it, it will never be there), so I believe the exception should be thrown. If it's not, then there's a bug in the docs.
(The scope is not an issue, this is just example code.)ancient-megabyte-79588
08/17/2020, 9:23 PMlittle-cartoon-10569
08/17/2020, 9:31 PMancient-megabyte-79588
08/18/2020, 3:03 PMOutput<>
, which will not necessarily be fulfilled at the time of creation since Output instantiations are usually deferred.
I 100% agree that when you ask the StackReference for an getRequired("name");
, if it doesn't exist, throw an exception but that is isn't the same as creating the initial StackReference object that you are using to get deferred objects.little-cartoon-10569
08/18/2020, 9:55 PMancient-megabyte-79588
08/18/2020, 10:38 PMAll of this should be doable synchronously and "catchably".I think this is the hard part. Provisioning cloud resources can't be done synchronously, unless you are willing to wait, even in the event that the provisioning failed. And a Stack is a cloud resource when it is being shared via StackReference.
little-cartoon-10569
08/18/2020, 10:41 PMancient-megabyte-79588
08/18/2020, 10:42 PMdependsOn
property that you can use to wait until the resource is provisioned, but in your case, your first stack/pulumi app may not have even run, so your still going to have a undefined string, and the app requesting the StackReference has to wait until another process has run.little-cartoon-10569
08/18/2020, 10:44 PMrequireOutputValue
, which has this doc?
Fetches the value promptly of the named stack output. Throws an error if the stack output is not found.
ancient-megabyte-79588
08/18/2020, 10:45 PMlittle-cartoon-10569
08/18/2020, 10:48 PMancient-megabyte-79588
08/18/2020, 10:51 PMlittle-cartoon-10569
08/18/2020, 10:52 PMancient-megabyte-79588
08/18/2020, 10:52 PMdependsOn
attribute.little-cartoon-10569
08/18/2020, 10:53 PMancient-megabyte-79588
08/18/2020, 10:54 PMOutput<T>
and automatically building in the dependency for you, but that still doesn't solve the problem that the dependency value doesn't currently exist.dependsOn
all of them and then when they are all complete, create the Peering.little-cartoon-10569
08/18/2020, 10:57 PMpulumi stack select
during a pulumi up
? Is it possible to depend on two things in two stacks at the same time? 🤔ancient-megabyte-79588
08/18/2020, 10:57 PMpulumi up
in as many separate console windows as my fast little fingers can type. 😄little-cartoon-10569
08/18/2020, 10:59 PMancient-megabyte-79588
08/18/2020, 10:59 PMpulumi up
on the same app on multiple stacks concurrently. Pulumi cli MIGHT stop that from happening. But in theory, you could run two stacks of the same app at the same time and they would not conflict.little-cartoon-10569
08/18/2020, 11:01 PMancient-megabyte-79588
08/18/2020, 11:02 PMdependsOn
functionality.little-cartoon-10569
08/18/2020, 11:02 PMancient-megabyte-79588
08/18/2020, 11:05 PMlittle-cartoon-10569
08/18/2020, 11:06 PMancient-megabyte-79588
08/18/2020, 11:07 PMlittle-cartoon-10569
08/18/2020, 11:43 PM