Hello, I wonder if `await` can be used in typescri...
# typescript
b
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
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
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
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...