Skip to content

Commit

Permalink
add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
badmintoncryer committed Nov 2, 2024
1 parent 7986dcd commit 6896b65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export enum ClusterType {
}

/**
* The Amazon Redshift operation to be performed
* The Amazon Redshift operation
*/
export enum ResourceAction {
/**
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit 6896b65

Please sign in to comment.