1
1
import ec2 = require( '@aws-cdk/aws-ec2' ) ;
2
+ import kms = require( '@aws-cdk/aws-kms' ) ;
2
3
import secretsmanager = require( '@aws-cdk/aws-secretsmanager' ) ;
3
4
import cdk = require( '@aws-cdk/cdk' ) ;
4
5
import { IClusterParameterGroup } from './cluster-parameter-group' ;
@@ -72,9 +73,19 @@ export interface DatabaseClusterProps {
72
73
defaultDatabaseName ?: string ;
73
74
74
75
/**
75
- * ARN of KMS key if you want to enable storage encryption
76
+ * Whether to enable storage encryption
77
+ *
78
+ * @default false
79
+ */
80
+ storageEncrypted ?: boolean
81
+
82
+ /**
83
+ * The KMS key for storage encryption. If specified `storageEncrypted`
84
+ * will be set to `true`.
85
+ *
86
+ * @default default master key
76
87
*/
77
- kmsKeyArn ?: string ;
88
+ kmsKey ?: kms . IEncryptionKey ;
78
89
79
90
/**
80
91
* A daily time range in 24-hours UTC format in which backups preferably execute.
@@ -91,6 +102,14 @@ export interface DatabaseClusterProps {
91
102
* @default No parameter group
92
103
*/
93
104
parameterGroup ?: IClusterParameterGroup ;
105
+
106
+ /**
107
+ * The CloudFormation policy to apply when the cluster and its instances
108
+ * are removed from the stack or replaced during an update.
109
+ *
110
+ * @default Retain
111
+ */
112
+ deleteReplacePolicy ?: cdk . DeletionPolicy
94
113
}
95
114
96
115
/**
@@ -261,10 +280,14 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
261
280
preferredMaintenanceWindow : props . preferredMaintenanceWindow ,
262
281
databaseName : props . defaultDatabaseName ,
263
282
// Encryption
264
- kmsKeyId : props . kmsKeyArn ,
265
- storageEncrypted : props . kmsKeyArn ? true : false ,
283
+ kmsKeyId : props . kmsKey && props . kmsKey . keyArn ,
284
+ storageEncrypted : props . kmsKey ? true : props . storageEncrypted
266
285
} ) ;
267
286
287
+ const deleteReplacePolicy = props . deleteReplacePolicy || cdk . DeletionPolicy . Retain ;
288
+ cluster . options . deletionPolicy = deleteReplacePolicy ;
289
+ cluster . options . updateReplacePolicy = deleteReplacePolicy ;
290
+
268
291
this . clusterIdentifier = cluster . ref ;
269
292
this . clusterEndpoint = new Endpoint ( cluster . dbClusterEndpointAddress , cluster . dbClusterEndpointPort ) ;
270
293
this . readerEndpoint = new Endpoint ( cluster . dbClusterReadEndpointAddress , cluster . dbClusterEndpointPort ) ;
@@ -303,6 +326,9 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
303
326
dbSubnetGroupName : subnetGroup . ref ,
304
327
} ) ;
305
328
329
+ instance . options . deletionPolicy = deleteReplacePolicy ;
330
+ instance . options . updateReplacePolicy = deleteReplacePolicy ;
331
+
306
332
// We must have a dependency on the NAT gateway provider here to create
307
333
// things in the right order.
308
334
instance . node . addDependency ( internetConnected ) ;
0 commit comments