Skip to content

Commit ef98b9f

Browse files
authored
feat(rds): deletion protection for RDS cluster (#9871)
Enable setting deletionProtection for a DatabaseCluster. Note - Marking as 'exempt-readme' as I don't think this is big enough to merit a README change. Feel free to disagree. fixes #6944 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1c9b733 commit ef98b9f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/@aws-cdk/aws-rds/lib/cluster.ts

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export interface DatabaseClusterProps {
8484
*/
8585
readonly defaultDatabaseName?: string;
8686

87+
/**
88+
* Indicates whether the DB cluster should have deletion protection enabled.
89+
*
90+
* @default false
91+
*/
92+
readonly deletionProtection?: boolean;
93+
8794
/**
8895
* Whether to enable storage encryption.
8996
*
@@ -425,6 +432,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
425432
port: props.port ?? clusterEngineBindConfig.port,
426433
dbClusterParameterGroupName: clusterParameterGroupConfig?.parameterGroupName,
427434
associatedRoles: clusterAssociatedRoles.length > 0 ? clusterAssociatedRoles : undefined,
435+
deletionProtection: props.deletionProtection,
428436
// Admin
429437
masterUsername: secret ? secret.secretValueFromJson('username').toString() : props.masterUser.username,
430438
masterUserPassword: secret

packages/@aws-cdk/aws-rds/test/test.cluster.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,33 @@ export = {
11781178
test.done();
11791179
},
11801180

1181+
'can set deletion protection'(test: Test) {
1182+
// GIVEN
1183+
const stack = testStack();
1184+
const vpc = new ec2.Vpc(stack, 'VPC');
1185+
1186+
// WHEN
1187+
new DatabaseCluster(stack, 'Database', {
1188+
engine: DatabaseClusterEngine.AURORA,
1189+
masterUser: {
1190+
username: 'admin',
1191+
password: cdk.SecretValue.plainText('tooshort'),
1192+
},
1193+
instanceProps: {
1194+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
1195+
vpc,
1196+
},
1197+
deletionProtection: true,
1198+
});
1199+
1200+
// THEN
1201+
expect(stack).to(haveResourceLike('AWS::RDS::DBCluster', {
1202+
DeletionProtection: true,
1203+
}));
1204+
1205+
test.done();
1206+
},
1207+
11811208
'does not throw (but adds a node error) if a (dummy) VPC does not have sufficient subnets'(test: Test) {
11821209
// GIVEN
11831210
const stack = testStack();

0 commit comments

Comments
 (0)