diff --git a/src/v2/components/acm-certificate/index.ts b/src/v2/components/acm-certificate/index.ts index 00f3945d..89906eec 100644 --- a/src/v2/components/acm-certificate/index.ts +++ b/src/v2/components/acm-certificate/index.ts @@ -10,6 +10,7 @@ export namespace AcmCertificate { */ subjectAlternativeNames?: pulumi.Input[]; hostedZoneId: pulumi.Input; + region?: pulumi.Input; }; } @@ -29,12 +30,17 @@ export class AcmCertificate extends pulumi.ComponentResource { domainName: args.domain, subjectAlternativeNames: args.subjectAlternativeNames, validationMethod: 'DNS', + region: args.region, tags: commonTags, }, { parent: this }, ); - this.createCertValidationRecords(args.domain, args.hostedZoneId); + this.createCertValidationRecords( + args.domain, + args.hostedZoneId, + args.region, + ); this.registerOutputs(); } @@ -42,6 +48,7 @@ export class AcmCertificate extends pulumi.ComponentResource { private createCertValidationRecords( domainName: AcmCertificate.Args['domain'], hostedZoneId: AcmCertificate.Args['hostedZoneId'], + region: AcmCertificate.Args['region'], ) { this.certificate.domainValidationOptions.apply(domains => { const validationRecords = domains.map( @@ -67,6 +74,7 @@ export class AcmCertificate extends pulumi.ComponentResource { { certificateArn: this.certificate.arn, validationRecordFqdns: validationRecords.map(record => record.fqdn), + region, }, { parent: this }, ); diff --git a/tests/acm-certificate/index.test.ts b/tests/acm-certificate/index.test.ts index 2b074948..2603a527 100644 --- a/tests/acm-certificate/index.test.ts +++ b/tests/acm-certificate/index.test.ts @@ -1,3 +1,4 @@ +import { alternateRegion } from './infrastructure/config'; import * as assert from 'node:assert'; import * as automation from '../automation'; import { InlineProgramArgs } from '@pulumi/pulumi/automation'; @@ -37,6 +38,7 @@ const ctx: AcmCertificateTestContext = { }, clients: { acm: new ACMClient({ region }), + acmAlternateRegion: new ACMClient({ region: alternateRegion }), route53: new Route53Client({ region }), }, }; @@ -139,4 +141,21 @@ describe('ACM Certificate component deployment', () => { 'Certificate should include all expected domains', ); }); + + it('should create certificate in alternate region', async () => { + const certificate = ctx.outputs.regionCertificate.value; + assert.ok(certificate.certificate, 'Should have certificate property'); + assert.ok(certificate.certificate.arn, 'Certificate should have ARN'); + + return backOff(async () => { + const certResult = await ctx.clients.acmAlternateRegion.send( + new DescribeCertificateCommand({ + CertificateArn: certificate.certificate.arn, + }), + ); + + const cert = certResult.Certificate; + assert.ok(cert, 'Certificate should exist'); + }, ctx.config.exponentialBackOffConfig); + }); }); diff --git a/tests/acm-certificate/infrastructure/config.ts b/tests/acm-certificate/infrastructure/config.ts new file mode 100644 index 00000000..0ecee376 --- /dev/null +++ b/tests/acm-certificate/infrastructure/config.ts @@ -0,0 +1,2 @@ +export const alternateRegion = + process.env.AWS_REGION === 'eu-central-1' ? 'us-west-1' : 'eu-central-1'; diff --git a/tests/acm-certificate/infrastructure/index.ts b/tests/acm-certificate/infrastructure/index.ts index f3984fe8..13b75c14 100644 --- a/tests/acm-certificate/infrastructure/index.ts +++ b/tests/acm-certificate/infrastructure/index.ts @@ -1,5 +1,6 @@ import { next as studion } from '@studion/infra-code-blocks'; import * as aws from '@pulumi/aws-v7'; +import { alternateRegion } from './config'; const appName = 'acm-certificate-test'; @@ -24,4 +25,10 @@ const sanCertificate = new studion.AcmCertificate( }, ); -export { certificate, sanCertificate, hostedZone }; +const regionCertificate = new studion.AcmCertificate(`${appName}-region-cert`, { + domain: `region.${domainName}`, + hostedZoneId: hostedZone.zoneId, + region: alternateRegion, +}); + +export { certificate, sanCertificate, regionCertificate, hostedZone }; diff --git a/tests/acm-certificate/test-context.ts b/tests/acm-certificate/test-context.ts index 7d4441a3..85e5a896 100644 --- a/tests/acm-certificate/test-context.ts +++ b/tests/acm-certificate/test-context.ts @@ -24,6 +24,7 @@ interface PulumiProgramContext { interface AwsContext { clients: { acm: ACMClient; + acmAlternateRegion: ACMClient; route53: Route53Client; }; }