From 3107af9ec94deee71382df9f3f1de1137d86fad7 Mon Sep 17 00:00:00 2001 From: Joshua Weber Date: Sun, 10 Jul 2022 18:41:27 +0200 Subject: [PATCH 1/2] :sparkles: feat(redshift): adds classic or elastic resize type option --- packages/@aws-cdk/aws-redshift/lib/cluster.ts | 9 +++ .../aws-redshift/test/cluster.test.ts | 67 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/packages/@aws-cdk/aws-redshift/lib/cluster.ts b/packages/@aws-cdk/aws-redshift/lib/cluster.ts index ab86540d3d7b3..4d044e7b18a15 100644 --- a/packages/@aws-cdk/aws-redshift/lib/cluster.ts +++ b/packages/@aws-cdk/aws-redshift/lib/cluster.ts @@ -322,6 +322,14 @@ export interface ClusterProps { * @default false */ readonly publiclyAccessible?: boolean + + /** + * A boolean value indicating whether the resize operation is using the classic resize process. + * If you don't provide this parameter or set the value to false, the resize type is elastic. + * + * @default - Elastic resize type + */ + readonly classicResizing?: boolean } /** @@ -485,6 +493,7 @@ export class Cluster extends ClusterBase { // Encryption kmsKeyId: props.encryptionKey?.keyId, encrypted: props.encrypted ?? true, + classic: props.classicResizing, }); cluster.applyRemovalPolicy(removalPolicy, { diff --git a/packages/@aws-cdk/aws-redshift/test/cluster.test.ts b/packages/@aws-cdk/aws-redshift/test/cluster.test.ts index 6db5f18ade684..80a03cb7ac207 100644 --- a/packages/@aws-cdk/aws-redshift/test/cluster.test.ts +++ b/packages/@aws-cdk/aws-redshift/test/cluster.test.ts @@ -422,6 +422,73 @@ test('default child returns a CfnCluster', () => { expect(cluster.node.defaultChild).toBeInstanceOf(CfnCluster); }); +test.each([ + ['elastic', false], + ['classic', true], +])('resize type (%s)', (_, classicResizing) => { + // WHEN + new Cluster(stack, 'Redshift', { + masterUser: { + masterUsername: 'admin', + masterPassword: cdk.SecretValue.unsafePlainText('tooshort'), + }, + classicResizing, + vpc, + }); + + // THEN + Template.fromStack(stack).hasResource('AWS::Redshift::Cluster', { + Properties: { + AllowVersionUpgrade: true, + MasterUsername: 'admin', + MasterUserPassword: 'tooshort', + ClusterType: 'multi-node', + AutomatedSnapshotRetentionPeriod: 1, + Encrypted: true, + NumberOfNodes: 2, + NodeType: 'dc2.large', + DBName: 'default_db', + PubliclyAccessible: false, + ClusterSubnetGroupName: { Ref: 'RedshiftSubnetsDFE70E0A' }, + VpcSecurityGroupIds: [{ 'Fn::GetAtt': ['RedshiftSecurityGroup796D74A7', 'GroupId'] }], + Classic: classicResizing, + }, + DeletionPolicy: 'Retain', + UpdateReplacePolicy: 'Retain', + }); +}); + +test('resize type not set', () => { + // WHEN + new Cluster(stack, 'Redshift', { + masterUser: { + masterUsername: 'admin', + masterPassword: cdk.SecretValue.unsafePlainText('tooshort'), + }, + vpc, + }); + + // THEN + Template.fromStack(stack).hasResource('AWS::Redshift::Cluster', { + Properties: { + AllowVersionUpgrade: true, + MasterUsername: 'admin', + MasterUserPassword: 'tooshort', + ClusterType: 'multi-node', + AutomatedSnapshotRetentionPeriod: 1, + Encrypted: true, + NumberOfNodes: 2, + NodeType: 'dc2.large', + DBName: 'default_db', + PubliclyAccessible: false, + ClusterSubnetGroupName: { Ref: 'RedshiftSubnetsDFE70E0A' }, + VpcSecurityGroupIds: [{ 'Fn::GetAtt': ['RedshiftSecurityGroup796D74A7', 'GroupId'] }], + }, + DeletionPolicy: 'Retain', + UpdateReplacePolicy: 'Retain', + }); +}); + function testStack() { const newTestStack = new cdk.Stack(undefined, undefined, { env: { account: '12345', region: 'us-test-1' } }); newTestStack.node.setContext('availability-zones:12345:us-test-1', ['us-test-1a', 'us-test-1b']); From 727b8249933f69714a2473a3819d908945f46ea5 Mon Sep 17 00:00:00 2001 From: Joshua Weber Date: Mon, 11 Jul 2022 21:25:44 +0200 Subject: [PATCH 2/2] :memo: Adds more information to the docstring --- packages/@aws-cdk/aws-redshift/lib/cluster.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-redshift/lib/cluster.ts b/packages/@aws-cdk/aws-redshift/lib/cluster.ts index 4d044e7b18a15..3a61f3ad93afe 100644 --- a/packages/@aws-cdk/aws-redshift/lib/cluster.ts +++ b/packages/@aws-cdk/aws-redshift/lib/cluster.ts @@ -324,8 +324,13 @@ export interface ClusterProps { readonly publiclyAccessible?: boolean /** - * A boolean value indicating whether the resize operation is using the classic resize process. - * If you don't provide this parameter or set the value to false, the resize type is elastic. + * If this flag is set, the cluster resizing type will be set to classic. + * When resizing a cluster, classic resizing will always provision a new cluster and transfer the data there. + * + * Classic resize takes more time to complete, but it can be useful in cases where the change in node count or + * the node type to migrate to doesn't fall within the bounds for elastic resize. + * + * @see https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-operations.html#elastic-resize * * @default - Elastic resize type */