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

feat(core): add a description parameter for the NestedStackProps #20930

Merged
merged 7 commits into from
Jul 8, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface MyNestedStackProps {
readonly siblingTopic?: sns.Topic; // a topic defined in a sibling nested stack
readonly topicCount: number;
readonly topicNamePrefix: string;
readonly description?: string;
}

class MyNestedStack extends NestedStack {
Expand All @@ -22,6 +23,7 @@ class MyNestedStack extends NestedStack {
parameters: {
[topicNamePrefixLogicalId]: props.topicNamePrefix, // pass in a parameter to the nested stack
},
description: props.description,
});

const topicNamePrefixParameter = new CfnParameter(this, 'TopicNamePrefix', { type: 'String' });
Expand Down Expand Up @@ -57,7 +59,7 @@ class MyTestStack extends Stack {
const queue = new sqs.Queue(this, 'SubscriberQueue');

new MyNestedStack(this, 'NestedStack1', { topicCount: 3, topicNamePrefix: 'Prefix1', subscriber: queue });
new MyNestedStack(this, 'NestedStack2', { topicCount: 2, topicNamePrefix: 'Prefix2' });
new MyNestedStack(this, 'NestedStack2', { topicCount: 2, topicNamePrefix: 'Prefix2', description: 'This is secound nested stack.' });
}
}

Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,16 @@ const stack = new Stack(app, 'StackName', {

By default, termination protection is disabled.

### Description

You can add a description of the stack in the same way as `StackProps`.

```ts
const stack = new Stack(app, 'StackName', {
description: 'This is a description.',
});
```

### CfnJson

`CfnJson` allows you to postpone the resolution of a JSON blob from
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/core/lib/nested-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export interface NestedStackProps {
* @default RemovalPolicy.DESTROY
*/
readonly removalPolicy?: RemovalPolicy;

/**
* A description of the stack.
*
* @default - No description.
*/
readonly description?: string;
}

/**
Expand Down Expand Up @@ -112,6 +119,7 @@ export class NestedStack extends Stack {
super(scope, id, {
env: { account: parentStack.account, region: parentStack.region },
synthesizer: new NestedStackSynthesizer(parentStack.synthesizer),
description: props.description,
});

this._parentStack = parentStack;
Expand Down
9 changes: 9 additions & 0 deletions packages/@aws-cdk/core/test/nested-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ describe('nested-stack', () => {
},
});
});
test('a nested-stack has a description in templateOptions.', () => {
const description = 'This is a description.';
const stack = new Stack();
var nestedStack = new NestedStack(stack, 'MyNestedStack', {
description,
});

expect(nestedStack.templateOptions.description).toEqual(description);
});
});
10 changes: 10 additions & 0 deletions packages/aws-cdk-lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,16 @@ const stack = new Stack(app, 'StackName', {

By default, termination protection is disabled.

### Description

You can add a description of the stack in the same way as `StackProps`.

```ts
const stack = new Stack(app, 'StackName', {
description: 'This is a description.',
});
```

### CfnJson

`CfnJson` allows you to postpone the resolution of a JSON blob from
Expand Down