https://pulumi.com logo
#typescript
Title
# typescript
d

dry-football-2639

10/05/2021, 12:49 PM
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

curved-pharmacist-41509

10/05/2021, 12:54 PM
You should be able to pulumi.output(aws.route53.getZone(..)) Then you can access .id on the output without doing anything special
e

echoing-actor-55539

10/06/2021, 12:43 AM
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),
  {}
);
47 Views