Hello, I’m just getting started with Pulumi and I’...
# typescript
s
Hello, I’m just getting started with Pulumi and I’m already stuck.
Copy code
import * as awsClassic from "@pulumi/aws";

const vpc = awsClassic.ec2.getVpcs({
    tags: {
        env: "staging"
    }
});

// Export a few interesting fields to make them easy to use:
export const vpcId = vpc.??
I get any properties on the
vpc
const. I think it’s because
ec2.getVpcs()
is returning a
Promise<GetVpcsResult>
. I have zero Typescript experience and I’m not sure how to handle the Promise return so I can retrieve Vpc properties from it. Maybe an
await
or something? Help!
b
hey Doug, welcome! yes, that returns a promise. You need to use
.then
to resolve it:
Copy code
const vpc = awsClassic.ec2.getVpcs({
    tags: {
        env: "staging"
    }
});

// Export a few interesting fields to make them easy to use:
export const vpcId = vpc.then(vpc => vpc.id)
However, you’re likely to want to use these values to pass to other resources, so I’d actually recommend using this:
Copy code
const vpc = awsClassic.ec2.getVpcsOutput({
    tags: {
        env: "staging"
    }
})

export const vpcId = vpc.id
an
Output
is a special Pulumi type which behaves very similarly to a promise, but Pulumi understands them better so you can pass them around easily. You might also want to give this a read: https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply It doesn’t talk specifically about promises, it talks about Pulumi outputs (which as I said, are similar) and it might help you wrap your head around it
s
@billowy-army-68599 thanks!
a
You can use a top level
await
but it requires some fiddling. I think the most important thing is to add
"type":"module"
to your
package.json
file.