I made a small component to handle DNS verificatio...
# getting-started
l
I made a small component to handle DNS verification of a certificate. However when calling this component twice in a pulumi program, it complains that the URN of one of the child resources is the same. Is it considered good practice to embed the name of a component resource within child resource logical IDs? I would have thought that the URN generation would do that automatically
For context, here is the component resource:
Copy code
class DnsValidatedCertificate extends pulumi.ComponentResource {
  certificate: aws.acm.Certificate
  constructor (name: string, props: DnsValidatedCertificateProps, opts?: pulumi.ComponentResourceOptions) {
    super('pkg:index:DnsValidatedCertificate', name, props, opts)

    this.certificate = new aws.acm.Certificate('certificate', props, { parent: this })

    const records: aws.route53.Record[] = []

    this.certificate.domainValidationOptions.apply((domainValidationOpts) => {
      for (const [i, domainValidationOpt] of domainValidationOpts.entries()) {
        records.push(new aws.route53.Record(`certificate-validation-record-${i}`, {
          allowOverwrite: true,
          zoneId: props.zoneId,
          name: domainValidationOpt.resourceRecordName,
          type: domainValidationOpt.resourceRecordType,
          records: [domainValidationOpt.resourceRecordValue],
          ttl: 60
        }, { parent: this }))
      }
    })
    new aws.acm.CertificateValidation('certificate-validation', {
      certificateArn: this.certificate.arn,
      validationRecordFqdns: records.map(record => record.fqdn)
    }, { parent: this })
  }
}
and the two resources in my program:
Copy code
this.certificate = new DnsValidatedCertificate('certificate', {
      domainName: props.dns.domainToDelegate,
      subjectAlternativeNames: [`*.${props.dns.domainToDelegate}`],
      validationMethod: 'DNS',
      zoneId: this.route53Zone.zoneId
    }, { parent: this }).certificate

    this.certificateUsEast1 = new DnsValidatedCertificate('certificate-us-east-1', {
      domainName: props.dns.domainToDelegate,
      subjectAlternativeNames: [`*.${props.dns.domainToDelegate}`],
      validationMethod: 'DNS',
      zoneId: this.route53Zone.zoneId
    }, { parent: this, provider: usEast1Provider }).certificate
I find it odd that Pulumi is complaining about the second cert having the same URN as the first, which implies I should be embedding the logical name I pass to the
DnsValidatedCertificate
constructor into the child resources
or I guess an alternative could be
super('pkg:index:DnsValidatedCertificate:' + name, name, props, opts)
d
This is currently a limitation, that child resources are scoped to the component class in URNs instead of a component instance as you're expecting. I've always prepended the component name for all resources in the past, but you're alternative might work too
l
Good to know that I wasn't just doing something wrong - thanks. I was too lazy to go through and change the IDs on all the resources so I tested out the alternative and it appears to work. Can you see any obvious downsides for doing it that way?
d
None that I can think of