Skip to content

Commit

Permalink
fix(rds): monitoringInterval in DatabaseClusterProps does not wor…
Browse files Browse the repository at this point in the history
…k with token (#33516)

### Issue # (if applicable)

Closes #33504.

### Reason for this change

`monitoringInterval` prop in `DatabaseClusterProps` should accept a token.

### Description of changes

Skip validations if `monitoringInterval` is a token.

### Describe any new or updated permissions being added

N/A

### Description of how you validated changes

Added a unit test.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Tietew authored Feb 21, 2025
1 parent 3b07346 commit f9b28b9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/aws-cdk-lib/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,10 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
if (props.enableClusterLevelEnhancedMonitoring && !props.monitoringInterval) {
throw new ValidationError('`monitoringInterval` must be set when `enableClusterLevelEnhancedMonitoring` is true.', this);
}
if (props.monitoringInterval && [0, 1, 5, 10, 15, 30, 60].indexOf(props.monitoringInterval.toSeconds()) === -1) {
if (
props.monitoringInterval && !props.monitoringInterval.isUnresolved() &&
[0, 1, 5, 10, 15, 30, 60].indexOf(props.monitoringInterval.toSeconds()) === -1
) {
throw new ValidationError(`'monitoringInterval' must be one of 0, 1, 5, 10, 15, 30, or 60 seconds, got: ${props.monitoringInterval.toSeconds()} seconds.`, this);
}

Expand Down
25 changes: 25 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,31 @@ describe('cluster', () => {
});
}).toThrow(`'monitoringInterval' must be one of 0, 1, 5, 10, 15, 30, or 60 seconds, got: ${monitoringInterval.toSeconds()} seconds.`);
});

test('accept token for monitoring interval', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');
const parameter = new cdk.CfnParameter(stack, 'MonitoringIntervalParameter', { type: 'Number' });

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.auroraMysql({ version: AuroraMysqlEngineVersion.VER_3_07_1 }),
credentials: {
username: 'admin',
password: cdk.SecretValue.unsafePlainText('tooshort'),
},
vpc,
writer: ClusterInstance.serverlessV2('writer'),
monitoringInterval: cdk.Duration.seconds(parameter.valueAsNumber),
enableClusterLevelEnhancedMonitoring: true,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBCluster', {
MonitoringInterval: { Ref: 'MonitoringIntervalParameter' },
});
});
});

test('addRotationSingleUser()', () => {
Expand Down

0 comments on commit f9b28b9

Please sign in to comment.