From 6896b65b31912904779e9ff541abdaebdfc24981 Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Sun, 3 Nov 2024 08:58:33 +0900 Subject: [PATCH] add validation --- .../@aws-cdk/aws-redshift-alpha/lib/cluster.ts | 6 +++++- .../aws-redshift-alpha/test/cluster.test.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts b/packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts index d5ac5e25ba8ef..1bfbf0cbeb260 100644 --- a/packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts +++ b/packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts @@ -81,7 +81,7 @@ export enum ClusterType { } /** - * The Amazon Redshift operation to be performed + * The Amazon Redshift operation */ export enum ResourceAction { /** @@ -613,6 +613,10 @@ export class Cluster extends ClusterBase { } } + if (props.resourceAction === ResourceAction.FAILOVER_PRIMARY_COMPUTE && !props.multiAz) { + throw new Error('ResourceAction.FAILOVER_PRIMARY_COMPUTE can only be used with multi-AZ clusters.'); + } + this.cluster = new CfnCluster(this, 'Resource', { // Basic allowVersionUpgrade: true, diff --git a/packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts b/packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts index a9720b8d46f21..82c595ecd3b7b 100644 --- a/packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts +++ b/packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts @@ -491,9 +491,23 @@ test.each([ }, vpc, resourceAction, + multiAz: true, }); }); +test.each([false, undefined])('throw error for failover primary compute action with single AZ cluster', (multiAz) => { + expect(() => { + new Cluster(stack, 'Redshift', { + masterUser: { + masterUsername: 'admin', + }, + vpc, + multiAz, + resourceAction: ResourceAction.FAILOVER_PRIMARY_COMPUTE, + }); + }).toThrow('ResourceAction.FAILOVER_PRIMARY_COMPUTE can only be used with multi-AZ clusters.') +}); + test('throws when trying to add rotation to a cluster without secret', () => { // WHEN const cluster = new Cluster(stack, 'Redshift', {