Skip to content

Commit 0a49927

Browse files
authored
fix(core): NestedStack defaultChild is undefined (#20450)
fixes #11221 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/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/master/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*
1 parent 1037b8c commit 0a49927

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export class NestedStack extends Stack {
140140
this.resource.applyRemovalPolicy(props.removalPolicy ?? RemovalPolicy.DESTROY);
141141

142142
this.nestedStackResource = this.resource;
143+
this.node.defaultChild = this.resource;
143144

144145
// context-aware stack name: if resolved from within this stack, return AWS::StackName
145146
// if resolved from the outer stack, use the { Ref } of the AWS::CloudFormation::Stack resource
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
Stack, NestedStack, CfnStack,
3+
} from '../lib';
4+
import { toCloudFormation } from './util';
5+
6+
describe('nested-stack', () => {
7+
test('a nested-stack has a defaultChild', () => {
8+
const stack = new Stack();
9+
var nestedStack = new NestedStack(stack, 'MyNestedStack');
10+
var cfn_nestedStack = (nestedStack.node.defaultChild) as CfnStack;
11+
cfn_nestedStack.addPropertyOverride('TemplateURL', 'http://my-url.com');
12+
expect(toCloudFormation(stack)).toEqual({
13+
Resources: {
14+
MyNestedStackNestedStackMyNestedStackNestedStackResource9C617903: {
15+
DeletionPolicy: 'Delete',
16+
Properties: {
17+
TemplateURL: 'http://my-url.com',
18+
},
19+
Type: 'AWS::CloudFormation::Stack',
20+
UpdateReplacePolicy: 'Delete',
21+
},
22+
},
23+
});
24+
});
25+
});

0 commit comments

Comments
 (0)