strong-megabyte-18664
07/23/2022, 2:07 AMimport * 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!billowy-army-68599
07/23/2022, 2:23 AM.then
to resolve it:
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:
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 itstrong-megabyte-18664
07/23/2022, 2:32 AMadorable-summer-21974
07/28/2022, 10:22 AMawait
but it requires some fiddling. I think the most important thing is to add "type":"module"
to your package.json
file.