Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rds): add support for update and backup properties to Cluster instances #10324

Merged
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ function createInstances(cluster: DatabaseClusterNew, props: DatabaseClusterBase
dbParameterGroupName: instanceParameterGroupConfig?.parameterGroupName,
monitoringInterval: props.monitoringInterval && props.monitoringInterval.toSeconds(),
monitoringRoleArn: monitoringRole && monitoringRole.roleArn,
autoMinorVersionUpgrade: props.instanceProps.autoMinorVersionUpgrade,
allowMajorVersionUpgrade: props.instanceProps.allowMajorVersionUpgrade,
deleteAutomatedBackups: props.instanceProps.deleteAutomatedBackups,
});

// If removalPolicy isn't explicitly set,
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ export interface InstanceProps {
* @default - default master key
*/
readonly performanceInsightEncryptionKey?: kms.IKey;

/**
* Whether to enable automatic upgrade of minor version for the DB instance.
*
* @default - true
*/
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
readonly autoMinorVersionUpgrade?: boolean;
/**
hixi-hyi marked this conversation as resolved.
Show resolved Hide resolved
* Whether to allow upgrade of major version for the DB instance.
*
* @default - true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really true by default? The documentation says:

Constraints: Major version upgrades must be allowed when specifying a value for the EngineVersion parameter that is a different major version than the DB instance's current version.

I guess that suggests that the default is, in fact, false...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely the default value for AllowMajorVersionUpgrade may be false.
Reading the documentation, this parameter may not be used routinely and is only needed when changing instance types, but I don't understand exactly what it is. (There was no value for AllowMajorVersionUpgrade in the results of aws rds describe-instances)

The @default value is currently written from the Cloudformation documentation.
However, I haven't programmatically set it, and its behavior is dependent on Cloudformation.

Should such a parameter be written as @default None? Or should I explicitly set true or false in the cdk?

I'd like to hear your opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not setting it and setting it to false provide the same result (as I believe it does in this case), it should be @default false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood. Thank you for your reply.
In fact, AllowMajorUpgrade is default false, and it seems to be necessary to add this parameter when upgrading the major version.

*/
readonly allowMajorVersionUpgrade?: boolean;
/**
hixi-hyi marked this conversation as resolved.
Show resolved Hide resolved
* Whether to remove automated backups immediately after the DB instance is deleted for the DB instance.
*
* @default - true
*/
readonly deleteAutomatedBackups?: boolean;
}

/**
Expand Down
75 changes: 75 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,81 @@ export = {
},
},

'cluster with disable automatic upgrade of minor version'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
masterUser: {
username: 'admin',
},
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
autoMinorVersionUpgrade: false,
vpc,
},
});

expect(stack).to(haveResource('AWS::RDS::DBInstance', {
AutoMinorVersionUpgrade: false,
}));

test.done();
},

'cluster with disallow upgrade of major version'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
masterUser: {
username: 'admin',
},
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
allowMajorVersionUpgrade: false,
vpc,
},
});

expect(stack).to(haveResource('AWS::RDS::DBInstance', {
AllowMajorVersionUpgrade: false,
}));

test.done();
},

'cluster with disallow remove backups'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
masterUser: {
username: 'admin',
},
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
deleteAutomatedBackups: false,
vpc,
},
});

expect(stack).to(haveResource('AWS::RDS::DBInstance', {
DeleteAutomatedBackups: false,
}));

test.done();
},

'create a cluster using a specific version of MySQL'(test: Test) {
// GIVEN
const stack = testStack();
Expand Down