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

fix(redshift): deploy fails when creating logging bucket without s3 key #21243

Merged
merged 6 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-redshift/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export interface ClusterProps {
readonly loggingBucket?: s3.IBucket

/**
* Prefix used for logging
* Prefix used for logging. Required if {@link ClusterProps.loggingBucket} is set.
*
* @default - no prefix
*/
Expand Down Expand Up @@ -474,6 +474,10 @@ export class Cluster extends ClusterBase {
this.singleUserRotationApplication = secretsmanager.SecretRotationApplication.REDSHIFT_ROTATION_SINGLE_USER;
this.multiUserRotationApplication = secretsmanager.SecretRotationApplication.REDSHIFT_ROTATION_MULTI_USER;

if (props.loggingBucket && !props.loggingKeyPrefix) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If these props need to be both or neither, I'd prefer we take loggingBucket and loggingKeyPrefix and make them into an interface that is optional, with both fields being required. I recognize that this is a breaking change, but I think it's the better contract overall. Since this is an experimental module, we can do this without a feature flag.

throw new Error('Cannot set loggingBucket without including an loggingKeyPrefix!');
}

let loggingProperties;
if (props.loggingBucket) {
loggingProperties = {
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-redshift/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,25 @@ test('can create a cluster with logging enabled', () => {
});
});

test('throws error when logging enabled without s3 prefix', () => {
// GIVEN
const bucket = s3.Bucket.fromBucketName(stack, 'bucket', 'logging-bucket');

// WHEN
const props = {
masterUser: {
masterUsername: 'admin',
},
vpc,
loggingBucket: bucket,
};

// THEN
expect(() => {
new Cluster(stack, 'Redshift', props);
}).toThrowError();
});

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