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(core): top-level resources cannot use long logical ids #6419

Merged
merged 3 commits into from
Feb 24, 2020
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
3 changes: 2 additions & 1 deletion packages/@aws-cdk/core/lib/private/uniqueid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const PATH_SEP = '/';

const HASH_LEN = 8;
const MAX_HUMAN_LEN = 240; // max ID len is 255
const MAX_ID_LEN = 255;

/**
* Calculates a unique ID for a set of textual components.
Expand All @@ -45,7 +46,7 @@ export function makeUniqueId(components: string[]) {
// top-level resources will simply use the `name` as-is in order to support
// transparent migration of cloudformation templates to the CDK without the
// need to rename all resources.
if (components.length === 1) {
if (components.length === 1 && components[0].length < MAX_ID_LEN) {
eladb marked this conversation as resolved.
Show resolved Hide resolved
return removeNonAlphanumeric(components[0]);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/core/test/test.logical-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export = {
test.done();
},

'if resource is top-level and logical id is longer than allowed, it is trimmed with a hash'(test: Test) {
// GIVEN
const stack = new Stack(undefined, 'TestStack');

// WHEN
const r = new CfnResource(stack, 'x'.repeat(256), { type: 'Resource' });

// THEN
test.equals(stack.resolve(r.logicalId), 'x'.repeat(240) + `C7A139A2`);
test.done();
},

'Logical IDs can be renamed at the stack level'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down