Skip to content

Commit 1dbae20

Browse files
authored
feat(rds): add missing PerformanceInsightRetention options (#25347)
We have a requirement to set PerformanceInsights retention to 2 months. Cfn supports it. Cdk should, too. *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0d187c1 commit 1dbae20

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

packages/aws-cdk-lib/aws-rds/lib/instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ export interface DatabaseInstanceNewProps {
538538
/**
539539
* The amount of time, in days, to retain Performance Insights data.
540540
*
541-
* @default 7
541+
* @default 7 this is the free tier
542542
*/
543543
readonly performanceInsightRetention?: PerformanceInsightRetention;
544544

packages/aws-cdk-lib/aws-rds/lib/props.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,16 +529,46 @@ export interface RotationMultiUserOptions extends CommonRotationUserOptions {
529529
}
530530

531531
/**
532-
* The retention period for Performance Insight.
532+
* The retention period for Performance Insight data, in days.
533+
*
534+
* Per https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbinstance.html#cfn-rds-dbinstance-performanceinsightsretentionperiod
535+
* This must be either
536+
* - 7 days (the default, free tier)
537+
* - month * 31, where month is a number of months from 1-23
538+
* - 731 (2 years)
533539
*/
534540
export enum PerformanceInsightRetention {
535541
/**
536542
* Default retention period of 7 days.
537543
*/
538544
DEFAULT = 7,
539545

546+
MONTHS_1 = 31,
547+
MONTHS_2 = 31 * 2,
548+
MONTHS_3 = 31 * 3,
549+
MONTHS_4 = 31 * 4,
550+
MONTHS_5 = 31 * 5,
551+
MONTHS_6 = 31 * 6,
552+
MONTHS_7 = 31 * 7,
553+
MONTHS_8 = 31 * 8,
554+
MONTHS_9 = 31 * 9,
555+
MONTHS_10 = 31 * 10,
556+
MONTHS_11 = 31 * 11,
557+
MONTHS_12 = 31 * 12,
558+
MONTHS_13 = 31 * 13,
559+
MONTHS_14 = 31 * 14,
560+
MONTHS_15 = 31 * 15,
561+
MONTHS_16 = 31 * 16,
562+
MONTHS_17 = 31 * 17,
563+
MONTHS_18 = 31 * 18,
564+
MONTHS_19 = 31 * 19,
565+
MONTHS_20 = 31 * 20,
566+
MONTHS_21 = 31 * 21,
567+
MONTHS_22 = 31 * 22,
568+
MONTHS_23 = 31 * 23,
569+
540570
/**
541571
* Long term retention period of 2 years.
542572
*/
543-
LONG_TERM = 731
573+
LONG_TERM = 731,
544574
}

packages/aws-cdk-lib/aws-rds/test/instance.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,44 @@ describe('instance', () => {
13491349
});
13501350
});
13511351

1352+
test.each<keyof typeof rds.PerformanceInsightRetention>([
1353+
'DEFAULT',
1354+
'MONTHS_1',
1355+
'MONTHS_2',
1356+
'MONTHS_3',
1357+
'MONTHS_4',
1358+
'MONTHS_5',
1359+
'MONTHS_6',
1360+
'MONTHS_7',
1361+
'MONTHS_8',
1362+
'MONTHS_9',
1363+
'MONTHS_10',
1364+
'MONTHS_11',
1365+
'MONTHS_12',
1366+
'MONTHS_13',
1367+
'MONTHS_14',
1368+
'MONTHS_15',
1369+
'MONTHS_16',
1370+
'MONTHS_17',
1371+
'MONTHS_18',
1372+
'MONTHS_19',
1373+
'MONTHS_20',
1374+
'MONTHS_21',
1375+
'MONTHS_22',
1376+
'MONTHS_23',
1377+
'LONG_TERM',
1378+
])('performance insights retention of %s', (performanceInsightRetentionKey) => {
1379+
new rds.DatabaseInstance(stack, 'Instance', {
1380+
engine: rds.DatabaseInstanceEngine.mysql({ version: rds.MysqlEngineVersion.VER_8_0_19 }),
1381+
vpc,
1382+
performanceInsightRetention: rds.PerformanceInsightRetention[performanceInsightRetentionKey],
1383+
});
1384+
1385+
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBInstance', {
1386+
PerformanceInsightsRetentionPeriod: rds.PerformanceInsightRetention[performanceInsightRetentionKey],
1387+
});
1388+
});
1389+
13521390
test('throws if performance insights fields are set but performance insights is disabled', () => {
13531391
expect(() => {
13541392
new rds.DatabaseInstance(stack, 'Instance', {

0 commit comments

Comments
 (0)