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

(cli): CDK Synth CLI command doesn't included stacks in nested cloud assemblies #28283

Open
haljarrett opened this issue Dec 7, 2023 · 2 comments
Labels
bug This issue is a bug. cli Issues related to the CDK CLI p2 package/tools Related to AWS CDK Tools or CLI

Comments

@haljarrett
Copy link

Describe the bug

When calling cdk synth on an app that has nested cloud assemblies (in this case, Stage subclass representing an application instance), the list of stacks printed after synthesis omits any stacks from the nested assembly.

This issue was described before, but closed when only part of the complaint was addressed: #18599

Expected Behavior

I would expect all synthesized stacks to be listed

Current Behavior

Only stacks that are direct children of the top level App are printed.

Reproduction Steps

I've constructed a reproduction here: https://github.com/haljarrett/cdk-stage-issue/tree/master

In it, I have an App with two top level Stacks and a Stage, which itself has a Stack. Only the two top level stacks are printed when cdk synth is executed:

$ cdk synth

Successfully synthesized to /Users/haljar/src/stage-issue/cdk.out
Supply a stack id (toplevelA, toplevelB) to display its template.

Compare this to the correct output of cdk list:

$ cdk list

toplevelA
toplevelB
beta/nested

Possible Solution

My thought is that this is arising from the way stacks are being selected from the root cloud assembly;

In cdk-toolkit.ts->synth we have the print statement generating this output, which uses stacks found from selectStackForDiff.

This method pulls the stacks from the root cloud assembly with assembly.selectStacks, specifying the behavior as MainAssembly on line 750. My suggestion would be to move this behavior to DefaultSelection.AllStacks, which would pull stacks recursively from nested assemblies.

Additional Information/Context

I am looking to move towards (and guide my team towards) using a CDK pattern that leverages Stage subclasses as the top level abstractionl; not being able to see / deploy the stacks that are built under a stage is a papercut when doing this.

CDK CLI Version

2.114.1 (build 02bbb1d)

Framework Version

No response

Node.js Version

v20.6.0

OS

MacOS

Language

TypeScript

Language Version

~5.2.2

Other information

Noted in the above, but unless there is a strong reason to only use stacks from the main assembly in this output, this should be a trivial fix - maybe if I find some time over the weekend I'll review the contribution guidelines and cut a PR.

@haljarrett haljarrett added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 7, 2023
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Dec 7, 2023
@tim-finnigan
Copy link

Thanks @haljarrett for reporting this issue. I can reproduce the behavior you described. In #14379 the MainAssembly line you referenced was previously defaultBehavior: DefaultSelection.AllStacks. I think some more review/discussion is needed on what the expected pattern should be here.

@tim-finnigan tim-finnigan added p2 cli Issues related to the CDK CLI and removed needs-triage This issue or PR still needs to be triaged. labels Dec 11, 2023
@haljarrett
Copy link
Author

Huh, good find - I can reproduce the behavior as described in that PR

$ cdk synth "**"

Successfully synthesized to /Users/XXXXX/src/stage-issue/cdk.out
Supply a stack id (toplevelA, toplevelB, beta/nested) to display its template.

I follow the reasoning for hiding sub-assembly stacks when all stacks nested in the node graph are NestedStacks, rolling up to some top-level stack, but Rico's comment on that PR touches on what I am hitting here (nesting a group of related stacks under non-stack construct).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. cli Issues related to the CDK CLI p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

2 participants