Skip to content

Commit

Permalink
fix(route53): support zone roots as record names (#2705)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoegertn authored and rix0rrr committed May 31, 2019
1 parent 3d4adfb commit 08a2852
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-route53/lib/records/_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IHostedZone } from '../hosted-zone-ref';
*
* @returns <ul>
* <li>If +providedName+ ends with a +.+, use it as-is</li>
* <li>If +providedName+ ends with +zoneName+, append a trailing +.+</li>
* <li>If +providedName+ ends with or equals +zoneName+, append a trailing +.+</li>
* <li>Otherwise, append +.+, +zoneName+ and a trailing +.+</li>
* </ul>
*/
Expand All @@ -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}.`;
}

Expand Down
36 changes: 36 additions & 0 deletions packages/@aws-cdk/aws-route53/test/test.alias-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

0 comments on commit 08a2852

Please sign in to comment.