Skip to content

Commit

Permalink
fix(core): NestedStack defaultChild is undefined (#20450)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
Jacco authored May 24, 2022
1 parent 1037b8c commit 0a49927
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/core/lib/nested-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class NestedStack extends Stack {
this.resource.applyRemovalPolicy(props.removalPolicy ?? RemovalPolicy.DESTROY);

this.nestedStackResource = this.resource;
this.node.defaultChild = this.resource;

// context-aware stack name: if resolved from within this stack, return AWS::StackName
// if resolved from the outer stack, use the { Ref } of the AWS::CloudFormation::Stack resource
Expand Down
25 changes: 25 additions & 0 deletions packages/@aws-cdk/core/test/nested-stack.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Stack, NestedStack, CfnStack,
} from '../lib';
import { toCloudFormation } from './util';

describe('nested-stack', () => {
test('a nested-stack has a defaultChild', () => {
const stack = new Stack();
var nestedStack = new NestedStack(stack, 'MyNestedStack');
var cfn_nestedStack = (nestedStack.node.defaultChild) as CfnStack;
cfn_nestedStack.addPropertyOverride('TemplateURL', 'http://my-url.com');
expect(toCloudFormation(stack)).toEqual({
Resources: {
MyNestedStackNestedStackMyNestedStackNestedStackResource9C617903: {
DeletionPolicy: 'Delete',
Properties: {
TemplateURL: 'http://my-url.com',
},
Type: 'AWS::CloudFormation::Stack',
UpdateReplacePolicy: 'Delete',
},
},
});
});
});

0 comments on commit 0a49927

Please sign in to comment.