From ecc9bf386ca088ca82a332c649f13613b9793628 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 9 Apr 2021 13:15:51 +0200 Subject: [PATCH] fix(route53): cannot set TTL to 0 (#14060) Closes #14039 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../@aws-cdk/aws-route53/lib/record-set.ts | 2 +- .../aws-route53/test/record-set.test.ts | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-route53/lib/record-set.ts b/packages/@aws-cdk/aws-route53/lib/record-set.ts index 566aea6d97a70..b880100ea60a4 100644 --- a/packages/@aws-cdk/aws-route53/lib/record-set.ts +++ b/packages/@aws-cdk/aws-route53/lib/record-set.ts @@ -212,7 +212,7 @@ export class RecordSet extends Resource implements IRecordSet { constructor(scope: Construct, id: string, props: RecordSetProps) { super(scope, id); - const ttl = props.target.aliasTarget ? undefined : ((props.ttl && props.ttl.toSeconds()) || 1800).toString(); + const ttl = props.target.aliasTarget ? undefined : ((props.ttl && props.ttl.toSeconds()) ?? 1800).toString(); const recordSet = new CfnRecordSet(this, 'Resource', { hostedZoneId: props.zone.hostedZoneId, diff --git a/packages/@aws-cdk/aws-route53/test/record-set.test.ts b/packages/@aws-cdk/aws-route53/test/record-set.test.ts index 682e2f327851e..136f88a27d426 100644 --- a/packages/@aws-cdk/aws-route53/test/record-set.test.ts +++ b/packages/@aws-cdk/aws-route53/test/record-set.test.ts @@ -68,6 +68,30 @@ nodeunitShim({ test.done(); }, + 'with ttl of 0'(test: Test) { + // GIVEN + const stack = new Stack(); + + const zone = new route53.HostedZone(stack, 'HostedZone', { + zoneName: 'myzone', + }); + + // WHEN + new route53.RecordSet(stack, 'Basic', { + zone, + recordName: 'aa', + recordType: route53.RecordType.CNAME, + target: route53.RecordTarget.fromValues('bbb'), + ttl: Duration.seconds(0), + }); + + // THEN + expect(stack).to(haveResource('AWS::Route53::RecordSet', { + TTL: '0', + })); + test.done(); + }, + 'defaults to zone root'(test: Test) { // GIVEN const stack = new Stack();