Skip to content

Commit

Permalink
fix(cli-lib): cannot bootstrap specific environment (#31713)
Browse files Browse the repository at this point in the history
### Issue

Closes #31656

### Reason for this change

When boostrapping, users may need to explicitly provide the environment if it can be determined from the app or shell environment. Previously this was not possible using the cli-lib-alpha package.

### Description of changes

Add a new argument to support environments.

### Description of how you validated changes

Unit test case was added.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mrgrain authored Oct 10, 2024
1 parent d80e3cd commit fec4bb1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/cli-lib-alpha/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export class AwsCdkCli implements IAwsCdkCli {
* cdk bootstrap
*/
public async bootstrap(options: BootstrapOptions = {}) {
const envs = options.environments ?? [];
const bootstrapCommandArgs: string[] = [
...envs,
...renderBooleanArg('force', options.force),
...renderBooleanArg('show-template', options.showTemplate),
...renderBooleanArg('terminationProtection', options.terminationProtection),
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/cli-lib-alpha/lib/commands/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { SharedOptions } from './common';
* Options to use with cdk bootstrap
*/
export interface BootstrapOptions extends SharedOptions {
/**
* The target AWS environments to deploy the bootstrap stack to.
* Uses the following format: `aws://<account-id>/<region>`
*
* @example "aws://123456789012/us-east-1"
* @default - Bootstrap all environments referenced in the CDK app or determine an environment from local configuration.
*/
readonly environments?: string[];

/**
* The name of the CDK toolkit stack to create
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/cli-lib-alpha/test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,16 @@ describe('list', () => {
);
});

test('bootstrap specific environment', async () => {
// WHEN
await cdk.bootstrap({
environments: ['aws://123456789012/us-east-1'],
});

// THEN
expect(jest.mocked(cli.exec)).toHaveBeenCalledWith(
['bootstrap', 'aws://123456789012/us-east-1', '--all'],
expect.anything(),
);
});
});

0 comments on commit fec4bb1

Please sign in to comment.