From 4aeb88349a23beace9d13495ff7c9db9ffc4d12e Mon Sep 17 00:00:00 2001 From: Shiv Lakshminarayan Date: Thu, 14 May 2020 01:20:00 -0700 Subject: [PATCH] fix(cli): cdk bootstrap cannot be used without supplying the --app argument (#7970) If a user supplied the `--app` argument, we select the environments from the app. However, we did not have a check that precludes this selection when the argument is not provided. We recently refactored this area in #7510 Closes #7906 --- packages/aws-cdk/lib/cdk-toolkit.ts | 6 +++++- packages/aws-cdk/test/cdk-toolkit.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 72fdf5f8b5e76..eaf5f3be69e6a 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -346,9 +346,13 @@ export class CdkToolkit { const environments: cxapi.Environment[] = [ ...environmentsFromDescriptors(environmentSpecs), - ...await globEnvironmentsFromStacks(await this.selectStacksForList([]), globSpecs, this.props.sdkProvider), ]; + // If there is an '--app' argument, select the environments from the app. + if (this.props.cloudExecutable.hasApp) { + environments.push(...await globEnvironmentsFromStacks(await this.selectStacksForList([]), globSpecs, this.props.sdkProvider)); + } + await Promise.all(environments.map(async (environment) => { success(' ⏳ Bootstrapping environment %s...', colors.blue(environment.name)); try { diff --git a/packages/aws-cdk/test/cdk-toolkit.test.ts b/packages/aws-cdk/test/cdk-toolkit.test.ts index 239745c7483a1..3ea25bfcd56cc 100644 --- a/packages/aws-cdk/test/cdk-toolkit.test.ts +++ b/packages/aws-cdk/test/cdk-toolkit.test.ts @@ -99,6 +99,29 @@ describe('deploy', () => { }, expect.anything(), expect.anything()); expect(mockBootstrapEnvironment).toHaveBeenCalledTimes(1); }); + + test('bootstrap can be invoked without the --app argument', async () => { + // GIVEN + cloudExecutable.configuration.settings.clear(); + const mockSynthesize = jest.fn(); + cloudExecutable.synthesize = mockSynthesize; + + const toolkit = defaultToolkitSetup(); + + // WHEN + await toolkit.bootstrap(['aws://123456789012/west-pole'], undefined, undefined, false, false, {}); + + // THEN + expect(mockBootstrapEnvironment).toHaveBeenCalledWith({ + account: '123456789012', + region: 'west-pole', + name: 'aws://123456789012/west-pole', + }, expect.anything(), expect.anything()); + expect(mockBootstrapEnvironment).toHaveBeenCalledTimes(1); + + expect(cloudExecutable.hasApp).toEqual(false); + expect(mockSynthesize).not.toHaveBeenCalled(); + }); }); });