From 76b5309182a6b217e11dfeb8d418de319e8e6185 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Fri, 21 Jun 2019 18:03:16 +0200 Subject: [PATCH] fix(route53): dummy hosted zone has right name (#2995) Be sure that the dummy hosted zone props that are returned before the actual lookup is done have the right domain name already. This is necessary to make DnsValidateCertificate's validation check succeed. Fixes #2076. --- .../test/test.dns-validated-certificate.ts | 35 +++++++++++++++++-- .../@aws-cdk/aws-route53/lib/hosted-zone.ts | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-certificatemanager/test/test.dns-validated-certificate.ts b/packages/@aws-cdk/aws-certificatemanager/test/test.dns-validated-certificate.ts index e6c39428962b6..5a07f63069e03 100644 --- a/packages/@aws-cdk/aws-certificatemanager/test/test.dns-validated-certificate.ts +++ b/packages/@aws-cdk/aws-certificatemanager/test/test.dns-validated-certificate.ts @@ -1,6 +1,6 @@ import { expect, haveResource } from '@aws-cdk/assert'; -import { PublicHostedZone } from '@aws-cdk/aws-route53'; -import { Stack } from '@aws-cdk/cdk'; +import { HostedZone, PublicHostedZone } from '@aws-cdk/aws-route53'; +import { App, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { DnsValidatedCertificate } from '../lib/dns-validated-certificate'; @@ -123,4 +123,35 @@ export = { })); test.done(); }, + + 'works with imported zone'(test: Test) { + // GIVEN + const app = new App(); + const stack = new Stack(app, 'Stack', { + env: { account: '12345678', region: 'us-blue-5' }, + }); + const imported = HostedZone.fromLookup(stack, 'ExampleDotCom', { + domainName: 'mydomain.com', + }); + + // WHEN + new DnsValidatedCertificate(stack, 'Cert', { + domainName: 'mydomain.com', + hostedZone: imported, + }); + + // THEN + expect(stack).to(haveResource('AWS::CloudFormation::CustomResource', { + ServiceToken: { + 'Fn::GetAtt': [ + 'CertCertificateRequestorFunction98FDF273', + 'Arn' + ] + }, + DomainName: 'mydomain.com', + HostedZoneId: 'DUMMY' + })); + + test.done(); + }, }; diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts index bba51a08e06f4..35aec1a5bba81 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts @@ -75,7 +75,7 @@ export class HostedZone extends Resource implements IHostedZone { public static fromLookup(scope: Construct, id: string, query: HostedZoneProviderProps): IHostedZone { const DEFAULT_HOSTED_ZONE: HostedZoneContextResponse = { Id: '/hostedzone/DUMMY', - Name: 'example.com', + Name: query.domainName, }; interface HostedZoneContextResponse {