@@ -10,7 +10,7 @@ import { DatabaseClusterAttributes, IDatabaseCluster } from './cluster-ref';
10
10
import { DatabaseSecret } from './database-secret' ;
11
11
import { Endpoint } from './endpoint' ;
12
12
import { IParameterGroup } from './parameter-group' ;
13
- import { BackupProps , InstanceProps , Login , RotationMultiUserOptions } from './props' ;
13
+ import { BackupProps , InstanceProps , Login , PerformanceInsightRetention , RotationMultiUserOptions } from './props' ;
14
14
import { DatabaseProxy , DatabaseProxyOptions , ProxyTarget } from './proxy' ;
15
15
import { CfnDBCluster , CfnDBInstance , CfnDBSubnetGroup } from './rds.generated' ;
16
16
@@ -563,8 +563,9 @@ export class DatabaseCluster extends DatabaseClusterBase {
563
563
throw new Error ( 'At least one instance is required' ) ;
564
564
}
565
565
566
+ const instanceProps = props . instanceProps ;
566
567
// Get the actual subnet objects so we can depend on internet connectivity.
567
- const internetConnected = props . instanceProps . vpc . selectSubnets ( props . instanceProps . vpcSubnets ) . internetConnectivityEstablished ;
568
+ const internetConnected = instanceProps . vpc . selectSubnets ( instanceProps . vpcSubnets ) . internetConnectivityEstablished ;
568
569
569
570
let monitoringRole ;
570
571
if ( props . monitoringInterval && props . monitoringInterval . toSeconds ( ) ) {
@@ -576,15 +577,21 @@ export class DatabaseCluster extends DatabaseClusterBase {
576
577
} ) ;
577
578
}
578
579
579
- const instanceType = props . instanceProps . instanceType ?? ec2 . InstanceType . of ( ec2 . InstanceClass . T3 , ec2 . InstanceSize . MEDIUM ) ;
580
- const instanceParameterGroupConfig = props . instanceProps . parameterGroup ?. bindToInstance ( { } ) ;
580
+ const enablePerformanceInsights = instanceProps . enablePerformanceInsights
581
+ || instanceProps . performanceInsightRetention !== undefined || instanceProps . performanceInsightEncryptionKey !== undefined ;
582
+ if ( enablePerformanceInsights && instanceProps . enablePerformanceInsights === false ) {
583
+ throw new Error ( '`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set' ) ;
584
+ }
585
+
586
+ const instanceType = instanceProps . instanceType ?? ec2 . InstanceType . of ( ec2 . InstanceClass . T3 , ec2 . InstanceSize . MEDIUM ) ;
587
+ const instanceParameterGroupConfig = instanceProps . parameterGroup ?. bindToInstance ( { } ) ;
581
588
for ( let i = 0 ; i < instanceCount ; i ++ ) {
582
589
const instanceIndex = i + 1 ;
583
590
const instanceIdentifier = props . instanceIdentifierBase != null ? `${ props . instanceIdentifierBase } ${ instanceIndex } ` :
584
591
props . clusterIdentifier != null ? `${ props . clusterIdentifier } instance${ instanceIndex } ` :
585
592
undefined ;
586
593
587
- const publiclyAccessible = props . instanceProps . vpcSubnets && props . instanceProps . vpcSubnets . subnetType === ec2 . SubnetType . PUBLIC ;
594
+ const publiclyAccessible = instanceProps . vpcSubnets && instanceProps . vpcSubnets . subnetType === ec2 . SubnetType . PUBLIC ;
588
595
589
596
const instance = new CfnDBInstance ( this , `Instance${ instanceIndex } ` , {
590
597
// Link to cluster
@@ -595,6 +602,11 @@ export class DatabaseCluster extends DatabaseClusterBase {
595
602
// Instance properties
596
603
dbInstanceClass : databaseInstanceType ( instanceType ) ,
597
604
publiclyAccessible,
605
+ enablePerformanceInsights : enablePerformanceInsights || instanceProps . enablePerformanceInsights , // fall back to undefined if not set
606
+ performanceInsightsKmsKeyId : instanceProps . performanceInsightEncryptionKey ?. keyArn ,
607
+ performanceInsightsRetentionPeriod : enablePerformanceInsights
608
+ ? ( instanceProps . performanceInsightRetention || PerformanceInsightRetention . DEFAULT )
609
+ : undefined ,
598
610
// This is already set on the Cluster. Unclear to me whether it should be repeated or not. Better yes.
599
611
dbSubnetGroupName : subnetGroup . ref ,
600
612
dbParameterGroupName : instanceParameterGroupConfig ?. parameterGroupName ,
0 commit comments