From 6083bc03c3a6b5371fb4f2b21b40b7cf74118469 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 14 Jun 2019 16:13:47 +0200 Subject: [PATCH] fix(rds): allow to deactivate instance backups The CloudFormation default is 1 day. Deactivating means setting to 0. --- packages/@aws-cdk/aws-rds/lib/instance.ts | 2 +- .../@aws-cdk/aws-rds/test/test.instance.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index 3ae8dd578f85e..5de824ccb45bf 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -507,7 +507,7 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData this.newCfnProps = { autoMinorVersionUpgrade: props.autoMinorVersionUpgrade, availabilityZone: props.multiAz ? undefined : props.availabilityZone, - backupRetentionPeriod: props.backupRetentionPeriod ? props.backupRetentionPeriod.toString() : undefined, + backupRetentionPeriod: props.backupRetentionPeriod !== undefined ? props.backupRetentionPeriod.toString() : undefined, copyTagsToSnapshot: props.copyTagsToSnapshot !== undefined ? props.copyTagsToSnapshot : true, dbInstanceClass: `db.${props.instanceClass}`, dbInstanceIdentifier: props.instanceIdentifier, diff --git a/packages/@aws-cdk/aws-rds/test/test.instance.ts b/packages/@aws-cdk/aws-rds/test/test.instance.ts index 7bcdabbc26165..0bdae5a52c3fd 100644 --- a/packages/@aws-cdk/aws-rds/test/test.instance.ts +++ b/packages/@aws-cdk/aws-rds/test/test.instance.ts @@ -406,6 +406,28 @@ export = { ] }); + test.done(); + }, + + 'can deactivate backup'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + // WHEN + new rds.DatabaseInstance(stack, 'Instance', { + engine: rds.DatabaseInstanceEngine.Mysql, + instanceClass: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), + masterUsername: 'admin', + vpc, + backupRetentionPeriod: 0, + }); + + // THEN + expect(stack).to(haveResource('AWS::RDS::DBInstance', { + BackupRetentionPeriod: '0' + })); + test.done(); } };