From 08a2852edf1bc7add7396590f33d2048d7b583ee Mon Sep 17 00:00:00 2001 From: Thorsten Hoeger Date: Fri, 31 May 2019 14:32:52 +0200 Subject: [PATCH] fix(route53): support zone roots as record names (#2705) --- .../@aws-cdk/aws-route53/lib/records/_util.ts | 4 +-- .../aws-route53/test/test.alias-record.ts | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-route53/lib/records/_util.ts b/packages/@aws-cdk/aws-route53/lib/records/_util.ts index b51a2f89620a8..ba503721f258c 100644 --- a/packages/@aws-cdk/aws-route53/lib/records/_util.ts +++ b/packages/@aws-cdk/aws-route53/lib/records/_util.ts @@ -11,7 +11,7 @@ import { IHostedZone } from '../hosted-zone-ref'; * * @returns */ @@ -21,7 +21,7 @@ export function determineFullyQualifiedDomainName(providedName: string, hostedZo } const suffix = `.${hostedZone.zoneName}`; - if (providedName.endsWith(suffix)) { + if (providedName.endsWith(suffix) || providedName === hostedZone.zoneName) { return `${providedName}.`; } diff --git a/packages/@aws-cdk/aws-route53/test/test.alias-record.ts b/packages/@aws-cdk/aws-route53/test/test.alias-record.ts index a44005631df18..412f0f271d17d 100644 --- a/packages/@aws-cdk/aws-route53/test/test.alias-record.ts +++ b/packages/@aws-cdk/aws-route53/test/test.alias-record.ts @@ -38,6 +38,42 @@ export = { } })); + test.done(); + }, + 'test alias record on zone root'(test: Test) { + // GIVEN + const stack = new Stack(); + const zone = new PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' }); + + const target: IAliasRecordTarget = { + bind: () => { + return { + hostedZoneId: 'Z2P70J7EXAMPLE', + dnsName: 'foo.example.com' + }; + } + }; + + // WHEN + new AliasRecord(zone, 'Alias', { + zone, + recordName: 'test.public', + target + }); + + // THEN - stack contains a record set + expect(stack).to(haveResource('AWS::Route53::RecordSet', { + Name: 'test.public.', + HostedZoneId: { + Ref: 'HostedZoneDB99F866' + }, + Type: 'A', + AliasTarget: { + HostedZoneId: 'Z2P70J7EXAMPLE', + DNSName: 'foo.example.com', + } + })); + test.done(); } };