Skip to content

(cli): deploy and destroy with --all option fails on apps with no top-level stacks #1003

@go-to-k

Description

@go-to-k

Describe the bug

When running cdk destroy --all or cdk deploy --all against a configuration with no top-level stacks (nested stages only), the following error occurs.

const app = new cdk.App();

new MyStage(app, 'MyStage'); // This has CdkSampleStack
> cdk deploy
Since this app includes more than a single stack, specify which stacks to use (wildcards are supported) or specify `--all`
Stacks: MyStage/CdkSampleStack

> cdk deploy --all # exits with status code 1 (error)
...
No stack found in the main cloud assembly. Use "list" to print manifest

> cdk destroy --all # exits with status code 1 (error)
...
No stack found in the main cloud assembly. Use "list" to print manifest

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

It can deploy/destroy all the stacks, or no errors occur, or a correct message / documentation is needed.

Current Behavior

It doesn't deploy/destroy all the stacks, and it exits with status code 1 (error).

Reproduction Steps

const app = new cdk.App();

new MyStage(app, 'MyStage'); // This has CdkSampleStack

export class MyStage extends Stage {
  constructor(scope: Construct, id: string, props?: StageProps) {
    super(scope, id, props);

    new CdkSampleStack(this, 'CdkSampleStack');
  }
}
> cdk deploy --all

> cdk destroy --all

Possible Solution

  • Make it deployable / destroyable
  • Or any of the following approaches:
    • Prevent errors
    • Correct messages
    • Correct documentation

Additional Information/Context

No response

CDK CLI Version

2.1100.1

Framework Version

No response

Node.js Version

24

OS

mac

Language

TypeScript

Language Version

No response

Other information

Is this a bug or by design?

The error message by cdk deploy/destroy (without --all) on the app

Since this app includes more than a single stack, specify which stacks to use (wildcards are supported) or specify --all

Since it says specify --all on the command, it may not be by design, or this message may not be appropriate.

Code

The --all option says that Deploy all available stacks or Deploy all stacks.

see: https://github.com/aws/aws-cdk-cli/blob/cdk%40v2.1100.1/packages/aws-cdk/lib/cli/cli-config.ts#L141

see: https://github.com/aws/aws-cdk-cli/blob/cdk%40v2.1100.1/packages/%40aws-cdk/cloud-assembly-schema/lib/integ-tests/commands/common.ts#L34-L41

'all': { type: 'boolean', desc: 'Deploy all available stacks', default: false },
  /**
   * Deploy all stacks
   *
   * Requried if `stacks` is not set
   *
   * @default - false
   */
  readonly all?: boolean;

The --all is passed into allTopLevel.

see: https://github.com/aws/aws-cdk-cli/blob/cdk%40v2.1100.1/packages/aws-cdk/lib/cli/cli.ts#L244

    const selector: StackSelector = {
      allTopLevel: args.all,
      patterns: args.STACKS,
    };

But the allTopLevel says that all stacks at the top level assembly. Looking at the doc, it seems like this is by design.

see: https://github.com/aws/aws-cdk-cli/blob/cdk%40v2.1100.1/packages/aws-cdk/lib/cxapp/cloud-assembly.ts#L80

export interface StackSelector {
  /**
   * Whether all stacks at the top level assembly should
   * be selected and nothing else
   */
  allTopLevel?: boolean;

There also appears to be a test that verifies this.

see: https://github.com/aws/aws-cdk-cli/blob/cdk%40v2.1100.1/packages/aws-cdk/test/cxapp/cloud-assembly.test.ts#L7-L18

test('select all top level stacks in the presence of nested assemblies', async () => {
  // GIVEN
  const cxasm = await testNestedCloudAssembly();

  // WHEN
  const x = await cxasm.selectStacks({ allTopLevel: true, patterns: [] }, { defaultBehavior: DefaultSelection.AllStacks });

  // THEN
  expect(x.stackCount).toBe(2);
  expect(x.stackIds).toContain('witherrors');
  expect(x.stackIds).toContain('withouterrors');
});

If it is by design

However, if it is by design that the Stage stacks cannot be deployed or deleted with --all, it is a bit confusing.

There is no documentation to understand that, and the error message says to specify --all. Furthermore, it seems like a bug that it terminates abnormally instead of normally.

Isn't some kind of action necessary?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions