https://pulumi.com logo
Title
b

bumpy-laptop-30846

03/04/2021, 11:17 AM
Hello, I wonder if
await
can be used in typescript. How do you use something like
aws.iam.User.get
which returns a promise without await in your
index.ts
?
a

ancient-megabyte-79588

03/04/2021, 4:27 PM
I don't normally see
await
in pulumi examples. What you do see is
<resource>.apply()
that returns a
pulumi.Output<T>
that the pulumi SDK knows will eventually be filled and everything that depends on the Output will wait for its fulfillment.
Basically, you need to build a long graph of dependent functions that will eventually be executed. Most of the pulumi SDK resources understand how to deal with a
pulumi.Output<T>
.
c

colossal-australia-65039

03/04/2021, 5:15 PM
another option is to put anything you want to await in an async function and just call that function in
index.ts
top-level awaits are also available in Typescript if you have the right tsconfig, though i haven't tried this before with Pulumi
✔️ 1
l

little-cartoon-10569

03/04/2021, 8:33 PM
Most resources take pulumi.Input for their parameters, which is a union type that includes Promise. So you can pass a Promise directly in an argument.
If you need to pass a thing in a Promise, I think you can wrap the Promise in an Output (using the
pulumi.output
function) then Pulumi will lift properties out of the Output as you need them.
But.. doesn't
aws.iam.User.get()
return a User? Not a Promise...