TypeScript question: How to handle `async/await` o...
# typescript
d
TypeScript question: How to handle 
async/await
 operations inside the ComponentResource constructor (like resource getters)? If I can't do 
await
 in the constructor, can I ever be sure that Pulumi will respect the dependency order (that the resources I pass as dependencies will be properly awaited before constructing the resource)?
Copy code
class DelegatedPublicDnsZone extends pulumi.ComponentResource {
  public output: DnsZone

  constructor(
    name: string,
    args: DelegatedPublicDnsZoneArgs,
    opts: pulumi.ComponentResourceOptions = {}
  ) {
    super('dixa:iac:DnsZone', name, {}, opts)

    const { zone, getConventionName } = args

    if (zone.id) {
      const r53Zone = await aws.route53.getZone({ <--- await cannon be used in constructor
        zoneId: zone.id,
      })
      this.output = {
        id: pulumi.output(r53Zone.id),
        domainName: pulumi.output(r53Zone.name),
      }
    }
c
You should be able to pulumi.output(aws.route53.getZone(..)) Then you can access .id on the output without doing anything special
e
I do something like this:
Copy code
export const siteZone = aws.route53.Zone.get(
  'siteZone',
  aws.route53.getZone(
    { name: '<http://my.zone.com|my.zone.com>', privateZone: false }
  ).then(zone => zone.id),
  {}
);
106 Views