Skip to content

Commit 443394c

Browse files
TomDufallmergify[bot]
authored andcommitted
feat(core): Add ability to set stack description (#4457) (#4477)
* Add description parameter to StackProps * Test new description StackProp
1 parent 1d1b8bc commit 443394c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

packages/@aws-cdk/core/lib/stack.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const STACK_SYMBOL = Symbol.for('@aws-cdk/core.Stack');
1717
const VALID_STACK_NAME_REGEX = /^[A-Za-z][A-Za-z0-9-]*$/;
1818

1919
export interface StackProps {
20+
/**
21+
* A description of the stack.
22+
*
23+
* @default - No description.
24+
*/
25+
readonly description?: string;
26+
2027
/**
2128
* The AWS environment (account/region) where this stack will be deployed.
2229
*
@@ -211,6 +218,15 @@ export class Stack extends Construct implements ITaggable {
211218
this.region = region;
212219
this.environment = environment;
213220

221+
if (props.description !== undefined) {
222+
// Max length 1024 bytes
223+
// Typically 2 bytes per character, may be more for more exotic characters
224+
if (props.description.length > 512) {
225+
throw new Error(`Stack description must be <= 1024 bytes. Received description: '${props.description}'`);
226+
}
227+
this.templateOptions.description = props.description;
228+
}
229+
214230
this._stackName = props.stackName !== undefined ? props.stackName : this.calculateStackName();
215231
this.tags = new TagManager(TagType.KEY_VALUE, 'aws:cdk:stack', props.tags);
216232

packages/@aws-cdk/core/test/test.stack.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ export = {
116116
test.done();
117117
},
118118

119+
'Stacks can have a description given to them'(test: Test) {
120+
const stack = new Stack(new App(), 'MyStack', { description: 'My stack, hands off!'});
121+
const output = toCloudFormation(stack);
122+
test.equal(output.Description, 'My stack, hands off!');
123+
test.done();
124+
},
125+
126+
'Stack descriptions have a limited length'(test: Test) {
127+
const desc = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
128+
incididunt ut labore et dolore magna aliqua. Consequat interdum varius sit amet mattis vulputate
129+
enim nulla aliquet. At imperdiet dui accumsan sit amet nulla facilisi morbi. Eget lorem dolor sed
130+
viverra ipsum. Diam volutpat commodo sed egestas egestas. Sit amet porttitor eget dolor morbi non.
131+
Lorem dolor sed viverra ipsum. Id porta nibh venenatis cras sed felis. Augue interdum velit euismod
132+
in pellentesque. Suscipit adipiscing bibendum est ultricies integer quis. Condimentum id venenatis a
133+
condimentum vitae sapien pellentesque habitant morbi. Congue mauris rhoncus aenean vel elit scelerisque
134+
mauris pellentesque pulvinar.
135+
Faucibus purus in massa tempor nec. Risus viverra adipiscing at in. Integer feugiat scelerisque varius
136+
morbi. Malesuada nunc vel risus commodo viverra maecenas accumsan lacus. Vulputate sapien nec sagittis
137+
aliquam malesuada bibendum arcu vitae. Augue neque gravida in fermentum et sollicitudin ac orci phasellus.
138+
Ultrices tincidunt arcu non sodales neque sodales.`;
139+
test.throws(() => new Stack(new App(), 'MyStack', { description: desc}));
140+
test.done();
141+
},
142+
119143
'Include should support non-hash top-level template elements like "Description"'(test: Test) {
120144
const stack = new Stack();
121145

0 commit comments

Comments
 (0)