Skip to content

Commit

Permalink
fix(rds): allow setting backupRetentionPeriod=0 (#2875)
Browse files Browse the repository at this point in the history
0 would get turned into `undefined` which would lead to the default value of 1.
  • Loading branch information
jogold authored and rix0rrr committed Jun 17, 2019
1 parent 936464f commit b0730dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

0 comments on commit b0730dd

Please sign in to comment.