Skip to content

Commit

Permalink
fix(redshift): tableNameSuffix evaluation (#17213)
Browse files Browse the repository at this point in the history
- Check if the generateSuffix is explicitly 'true';
- Closes #17064


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ibrahimcesar authored Nov 11, 2021
1 parent 8fa293a commit f7c3217
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ClusterProps, executeStatement } from './util';

export async function handler(props: TableHandlerProps & ClusterProps, event: AWSLambda.CloudFormationCustomResourceEvent) {
const tableNamePrefix = props.tableName.prefix;
const tableNameSuffix = props.tableName.generateSuffix ? `${event.RequestId.substring(0, 8)}` : '';
const tableNameSuffix = props.tableName.generateSuffix === 'true' ? `${event.RequestId.substring(0, 8)}` : '';
const tableColumns = props.tableColumns;
const clusterProps = props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface UserHandlerProps {
export interface TableHandlerProps {
readonly tableName: {
readonly prefix: string;
readonly generateSuffix: boolean;
readonly generateSuffix: string;
};
readonly tableColumns: Column[];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-redshift/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class Table extends TableBase {
properties: {
tableName: {
prefix: props.tableName ?? cdk.Names.uniqueId(this),
generateSuffix: !props.tableName,
generateSuffix: !props.tableName ? 'true' : 'false',
},
tableColumns: this.tableColumns,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const physicalResourceId = 'PhysicalResourceId';
const resourceProperties = {
tableName: {
prefix: tableNamePrefix,
generateSuffix: true,
generateSuffix: 'true',
},
tableColumns,
clusterName,
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('create', () => {
...resourceProperties,
tableName: {
...resourceProperties.tableName,
generateSuffix: false,
generateSuffix: 'false',
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@
"databaseName": "my_db",
"tableName": {
"prefix": "awscdkredshiftclusterdatabaseTable24923533",
"generateSuffix": true
"generateSuffix": "true"
},
"tableColumns": [
{
Expand Down Expand Up @@ -1412,4 +1412,4 @@
"Description": "Artifact hash for asset \"daeb79e3cee39c9b902dc0d5c780223e227ed573ea60976252947adab5fb2be1\""
}
}
}
}
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-redshift/test/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('cluster table', () => {
Template.fromStack(stack).hasResourceProperties('Custom::RedshiftDatabaseQuery', {
tableName: {
prefix: 'Table',
generateSuffix: true,
generateSuffix: 'true',
},
tableColumns,
});
Expand All @@ -67,7 +67,7 @@ describe('cluster table', () => {
Template.fromStack(stack).hasResourceProperties('Custom::RedshiftDatabaseQuery', {
tableName: {
prefix: tableName,
generateSuffix: false,
generateSuffix: 'false',
},
});
});
Expand Down

0 comments on commit f7c3217

Please sign in to comment.