Skip to content

Commit

Permalink
fix(cli): cdk bootstrap cannot be used without supplying the --app ar…
Browse files Browse the repository at this point in the history
…gument (#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
  • Loading branch information
shivlaks committed May 14, 2020
1 parent 3b1d0db commit 540a7e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions packages/aws-cdk/test/cdk-toolkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

Expand Down

0 comments on commit 540a7e6

Please sign in to comment.