Skip to content

Commit

Permalink
feat(core): add a description parameter for the NestedStackProps (#20930
Browse files Browse the repository at this point in the history
)

This PR adds a description parameter for the NestedStackProps.

Fixes #16337

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
joe-king-sh committed Jul 8, 2022
1 parent 02099e1 commit 5ef106b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
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 @@ -995,6 +995,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 @@ -1026,6 +1026,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

0 comments on commit 5ef106b

Please sign in to comment.