Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cloudformation] NestedStack doesn't have defaultChild #11221

Closed
edisongustavo opened this issue Oct 30, 2020 · 6 comments · Fixed by #20450
Closed

[cloudformation] NestedStack doesn't have defaultChild #11221

edisongustavo opened this issue Oct 30, 2020 · 6 comments · Fixed by #20450
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1

Comments

@edisongustavo
Copy link
Contributor

I get an undefined object when I access the attribute defaultChild from a NestedStack's node.

Reproduction Steps

I tried this code on https://play-with-cdk.com/

import * as cdk from '@aws-cdk/core';

import { CfnStack, NestedStack } from '@aws-cdk/aws-cloudformation';

// Keep the class name stable please
export class AppStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);
    
        // Add your code here
        var nestedStack = new NestedStack(this, 'MyNestedStack');
        var cfn_nestedStack = (nestedStack.node.defaultChild) as CfnStack;
        cfn_nestedStack.addPropertyOverride('TemplateURL', 'http://my-url.com');
    }
}

What did you expect to happen?

The stack to be synthesized without errors and with the TemplateURL parameter of the stack overriden.

What actually happened?

The synth crashes with this error:

TypeError: Cannot read property 'addPropertyOverride' of undefined

Environment

I have also tried it with Python and the same error happens.

  • CLI Version : 1.59.0
  • Framework Version: 1.59.0
  • Node.js Version:
  • OS : Ubuntu 18.04
  • Language (Version): all

Other


This is 🐛 Bug Report

@edisongustavo edisongustavo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 30, 2020
@github-actions github-actions bot added the @aws-cdk/aws-cloudformation Related to AWS CloudFormation label Oct 30, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 2, 2020

You are very correct. It needs to be assigned as it has a non-standard name.

@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1 labels Nov 2, 2020
@edisongustavo
Copy link
Contributor Author

@rix0rrr is there a workaround in the mean time?

I'm confused from your answer because if I call the children property, then I get a list of length 0.

@edisongustavo
Copy link
Contributor Author

edisongustavo commented Nov 2, 2020

I have also tried this on version 1.71.0 with the same result.

@edisongustavo
Copy link
Contributor Author

I found the workaround for NestedStack. It is a simple matter of using the nestedStackResource property instead of node.defaultChild.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Nov 2, 2020
@Jacco
Copy link
Contributor

Jacco commented May 21, 2022

@rix0rrr created a PR for this (my first)

@mergify mergify bot closed this as completed in #20450 May 24, 2022
mergify bot pushed a commit that referenced this issue May 24, 2022
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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants