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

calm-quill-21760

02/24/2020, 5:34 PM
I'm new to Pulumi. I've noticed that pulumi.all is equivalent to Promise.all and .apply() is similar to .then(). What seems to be missing is an equivalent for await. That feels like a step back in time to using chained .then() statements. I've noticed I can wrap it in a promise sort of like this:
Copy code
return new Promise(resolve => return pulumi.output(variable_name).apply(val => {resolve (val);})
The returned object looks correct, though Typescript seems to have lost all concept of the object types being returned. This makes me think about the AWS SDK where you can add .promise() to the end of a number of calls to work cleanly with await. I'm far from being a Typescript guru, but how difficult is it to have something similar in Pulumi?
w

white-balloon-205

02/24/2020, 5:37 PM
You are exactly right in your analogies. TypeScript (really JavaScript) doesn't provide any way to offer generalized
await
syntax over other types of data. Despite the analogy, note that in Pulumi, 90%+ of the time
Output
is used quite differently than
Promise
is used in other APIs.
Outputs
are primarily data you pass from one place (the output of a resource) to another (the input of another resource), transforming the value along the way. This is different than common use of
Promise
in may JS APIs where it is used for control-flow. The result is that in common usage, you shouldn't need to use something like
await
on Outputs, and indeed if it was available it would encourage patterns that are not ideal for Pulumi (like creating resources "inside apply", which can lead to inaccurate previews).
c

calm-quill-21760

02/24/2020, 5:48 PM
Makes sense. My use case is configuration-driven code where I'm taking the created output information and comparing to configuration information in JSON objects. Hence the need to be able to extract the created values. For example, I create three VPCs, then subnets, and finally peering connections, each in a separate section of code. Tying together the configuration of each of these objects requires knowing the cidrBlock, VPC IDs, etc. Controlling these from JSON configuration is relatively straightforward, but I have to be able to see inside the created objects to know which ones to match up.
w

white-balloon-205

02/24/2020, 5:49 PM
To first approximation - can't you just pass outputs from one resource to inputs of another (with a couple
.all.apply
s to convert a set of outputs into a single input)?
c

calm-quill-21760

02/24/2020, 5:53 PM
In simple cases, yes, that works just great and Pulumi knows how to order resource creation to get it all done. Where I encountered enormous difficulty was creating routes for subnets across peering links.
w

white-balloon-205

02/24/2020, 5:54 PM
Got it. I'd be interested in seeing the code you ended up needing for that.
c

calm-quill-21760

02/24/2020, 5:56 PM
I did get it working, but I feel like it could/should be so much cleaner.
I have the code in a Bitbucket repo. If you send me your username, I can share it with you. Otherwise let me know the best way to share it.
w

white-balloon-205

02/24/2020, 7:01 PM
Sounds good - I’m
lukehoban
.
c

calm-quill-21760

02/24/2020, 7:04 PM
Bitbucket doesn't recognize your username, probably because we're in different organizations. I took a guess at your email address. Let me know if you don't get the invite.