Skip to content

Commit 08a2852

Browse files
hoegertnrix0rrr
authored andcommitted
fix(route53): support zone roots as record names (#2705)
1 parent 3d4adfb commit 08a2852

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

packages/@aws-cdk/aws-route53/lib/records/_util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IHostedZone } from '../hosted-zone-ref';
1111
*
1212
* @returns <ul>
1313
* <li>If +providedName+ ends with a +.+, use it as-is</li>
14-
* <li>If +providedName+ ends with +zoneName+, append a trailing +.+</li>
14+
* <li>If +providedName+ ends with or equals +zoneName+, append a trailing +.+</li>
1515
* <li>Otherwise, append +.+, +zoneName+ and a trailing +.+</li>
1616
* </ul>
1717
*/
@@ -21,7 +21,7 @@ export function determineFullyQualifiedDomainName(providedName: string, hostedZo
2121
}
2222

2323
const suffix = `.${hostedZone.zoneName}`;
24-
if (providedName.endsWith(suffix)) {
24+
if (providedName.endsWith(suffix) || providedName === hostedZone.zoneName) {
2525
return `${providedName}.`;
2626
}
2727

packages/@aws-cdk/aws-route53/test/test.alias-record.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,42 @@ export = {
3838
}
3939
}));
4040

41+
test.done();
42+
},
43+
'test alias record on zone root'(test: Test) {
44+
// GIVEN
45+
const stack = new Stack();
46+
const zone = new PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' });
47+
48+
const target: IAliasRecordTarget = {
49+
bind: () => {
50+
return {
51+
hostedZoneId: 'Z2P70J7EXAMPLE',
52+
dnsName: 'foo.example.com'
53+
};
54+
}
55+
};
56+
57+
// WHEN
58+
new AliasRecord(zone, 'Alias', {
59+
zone,
60+
recordName: 'test.public',
61+
target
62+
});
63+
64+
// THEN - stack contains a record set
65+
expect(stack).to(haveResource('AWS::Route53::RecordSet', {
66+
Name: 'test.public.',
67+
HostedZoneId: {
68+
Ref: 'HostedZoneDB99F866'
69+
},
70+
Type: 'A',
71+
AliasTarget: {
72+
HostedZoneId: 'Z2P70J7EXAMPLE',
73+
DNSName: 'foo.example.com',
74+
}
75+
}));
76+
4177
test.done();
4278
}
4379
};

0 commit comments

Comments
 (0)