-
Notifications
You must be signed in to change notification settings - Fork 4k
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): Add stage prefix to stack name shortening process #24443
Changes from 13 commits
8abb431
668539c
6c1532b
7f06cd7
b28f46f
0cf310a
b126e20
1f5b03b
b151d21
b1aee08
ecfc9cb
297273a
16e96c1
0e28b23
f52804e
adecdbc
f979e85
e9cd174
c6c6053
7655cd2
56bd828
5dd29bc
729f23e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1424,7 +1424,7 @@ export class Stack extends Construct implements ITaggable { | |
private generateStackName() { | ||
const assembly = Stage.of(this); | ||
const prefix = (assembly && assembly.stageName) ? `${assembly.stageName}-` : ''; | ||
return `${prefix}${this.generateStackId(assembly)}`; | ||
return `${this.generateStackId(assembly, prefix)}`; | ||
} | ||
|
||
/** | ||
|
@@ -1439,7 +1439,7 @@ export class Stack extends Construct implements ITaggable { | |
/** | ||
* Generate an ID with respect to the given container construct. | ||
*/ | ||
private generateStackId(container: IConstruct | undefined) { | ||
private generateStackId(container: IConstruct | undefined, prefix: string='') { | ||
const rootPath = rootPathTo(this, container); | ||
const ids = rootPath.map(c => Node.of(c).id); | ||
|
||
|
@@ -1449,7 +1449,7 @@ export class Stack extends Construct implements ITaggable { | |
throw new Error('unexpected: stack id must always be defined'); | ||
} | ||
|
||
return makeStackName(ids); | ||
return makeStackName(ids, prefix); | ||
} | ||
|
||
private resolveExportedValue(exportedValue: any): ResolvedExport { | ||
|
@@ -1635,9 +1635,14 @@ export function rootPathTo(construct: IConstruct, ancestor?: IConstruct): IConst | |
* has only one component. Otherwise we fall back to the regular "makeUniqueId" | ||
* behavior. | ||
*/ | ||
function makeStackName(components: string[]) { | ||
if (components.length === 1) { return components[0]; } | ||
return makeUniqueResourceName(components, { maxLength: 128 }); | ||
function makeStackName(components: string[], prefix: string='') { | ||
if (components.length === 1) { | ||
const stack_name = prefix + components[0]; | ||
if (stack_name.length <= 128) { | ||
return prefix + components[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there is a single component and a prefix, passing both the components and the prefix to the |
||
} | ||
} | ||
return makeUniqueResourceName(components, { maxLength: 128 }, prefix); | ||
} | ||
|
||
function getCreateExportsScope(stack: Stack) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix is added after the hash calculation to preserver the same hash for already existing stacks that fall within this scenario.
I'm not sure if I'm worrying too much, as I'm not sure what happens if you create a stack with CDK, then after this change you run CDK again, and the old created stack's name does not match the new name generated.