diff --git a/packages/@aws-cdk/core/lib/nested-stack.ts b/packages/@aws-cdk/core/lib/nested-stack.ts index e1248d69888aa..4859ae0894489 100644 --- a/packages/@aws-cdk/core/lib/nested-stack.ts +++ b/packages/@aws-cdk/core/lib/nested-stack.ts @@ -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 diff --git a/packages/@aws-cdk/core/test/nested-stack.test.ts b/packages/@aws-cdk/core/test/nested-stack.test.ts new file mode 100644 index 0000000000000..b1508e8bf148f --- /dev/null +++ b/packages/@aws-cdk/core/test/nested-stack.test.ts @@ -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', + }, + }, + }); + }); +}); \ No newline at end of file