Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
},
},
});
});
});