Skip to content

Commit

Permalink
update integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
badmintoncryer committed Nov 2, 2024
1 parent 796c6d1 commit 7986dcd
Show file tree
Hide file tree
Showing 12 changed files with 1,731 additions and 1 deletion.
42 changes: 42 additions & 0 deletions packages/@aws-cdk/aws-redshift-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,48 @@ cluster.addToParameterGroup('enable_user_activity_logging', 'true');
cluster.enableRebootForParameterChanges()
```

## Resource Action

You can perform various actions on the Redshift resource by specifying the `resourceAction` property,
including [pausing and resuming the cluster](https://docs.aws.amazon.com/redshift/latest/mgmt/rs-mgmt-pause-resume-cluster.html), as well as initiating [failover for Multi-AZ clusters](https://docs.aws.amazon.com/redshift/latest/mgmt/test-cluster-multi-az.html).

```ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import { ResourceAction } from '@aws-cdk/aws-redshift-alpha';

declare const vpc: ec2.IVpc;

// Pause the cluster
new Cluster(this, 'PausedCluster', {
masterUser: {
masterUsername: 'admin',
},
vpc,
resourceAction: ResourceAction.PAUSE,
});

// Resume the cluster
new Cluster(this, 'ResumedCluster', {
masterUser: {
masterUsername: 'admin',
},
vpc,
resourceAction: ResourceAction.RESUME,
});

// Failover the cluster
new Cluster(this, 'FailOverCluster', {
masterUser: {
masterUsername: 'admin',
},
// VPC must have 3 AZs for the cluster which executes failover action
vpc,
// Must be a multi-AZ cluster to failover
multiAz: true,
resourceAction: ResourceAction.FAILOVER_PRIMARY_COMPUTE,
});
```

## Elastic IP

If you configure your cluster to be publicly accessible, you can optionally select an *elastic IP address* to use for the external IP address. An elastic IP address is a static IP address that is associated with your AWS account. You can use an elastic IP address to connect to your cluster from outside the VPC. An elastic IP address gives you the ability to change your underlying configuration without affecting the IP address that clients use to connect to your cluster. This approach can be helpful for situations such as recovery after a failure.
Expand Down
30 changes: 30 additions & 0 deletions packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ export enum ClusterType {
MULTI_NODE = 'multi-node',
}

/**
* The Amazon Redshift operation to be performed
*/
export enum ResourceAction {
/**
* Pause the cluster
*/
PAUSE_CLUSTER = 'pause-cluster',

/**
* Resume the cluster
*/
RESUME_CLUSTER = 'resume-cluster',

/**
* Failing over to the other availability zone
*
* @see https://docs.aws.amazon.com/redshift/latest/mgmt/test-cluster-multi-az.html
*/
FAILOVER_PRIMARY_COMPUTE = 'failover-primary-compute',
}

/**
* Username and password combination
*/
Expand Down Expand Up @@ -399,6 +421,13 @@ export interface ClusterProps {
* @default - false
*/
readonly multiAz?: boolean;

/**
* The Amazon Redshift operation to be performed.
*
* @default - no operation
*/
readonly resourceAction?: ResourceAction;
}

/**
Expand Down Expand Up @@ -613,6 +642,7 @@ export class Cluster extends ClusterBase {
elasticIp: props.elasticIp,
enhancedVpcRouting: props.enhancedVpcRouting,
multiAz: props.multiAz,
resourceAction: props.resourceAction,
});

this.cluster.applyRemovalPolicy(removalPolicy, {
Expand Down
17 changes: 16 additions & 1 deletion packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as iam from 'aws-cdk-lib/aws-iam';
import * as kms from 'aws-cdk-lib/aws-kms';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as cdk from 'aws-cdk-lib';
import { Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterType, NodeType } from '../lib';
import { Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterType, NodeType, ResourceAction } from '../lib';
import { CfnCluster } from 'aws-cdk-lib/aws-redshift';

let stack: cdk.Stack;
Expand Down Expand Up @@ -479,6 +479,21 @@ test('can create a cluster with logging enabled', () => {
});
});

test.each([
ResourceAction.PAUSE_CLUSTER,
ResourceAction.RESUME_CLUSTER,
ResourceAction.FAILOVER_PRIMARY_COMPUTE,
])('specify resource action %s', (resourceAction) => {
// WHEN
new Cluster(stack, 'Redshift', {
masterUser: {
masterUsername: 'admin',
},
vpc,
resourceAction,
});
});

test('throws when trying to add rotation to a cluster without secret', () => {
// WHEN
const cluster = new Cluster(stack, 'Redshift', {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7986dcd

Please sign in to comment.