From 44134adfe8701c4e5b51ae3a34cd1d09f91735ec Mon Sep 17 00:00:00 2001 From: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com> Date: Mon, 16 Sep 2024 06:09:02 -0400 Subject: [PATCH] fix(cli): bootstrap respects qualifier from cdk.json (#31410) closes #28249. The qualifier property can be set via the context key "@aws-cdk/core:bootstrapQualifier" and if omitted, the arbitrary default is `hnb659fds`. In the case of `cdk bootstrap`, there is an additional way to set the qualifier via the `--qualifier` CLI option. Specific to the `cdk bootstrap` logic, we currently only honor the command line argument, which is an error. Ultimately, the following `cdk bootstrap` calls should be identical: - `cdk bootstrap` with the following `cdk.json` file: ```json { "@aws-cdk/core:bootstrapQualifier": "abcde", } ``` - `cdk bootstrap --qualifier="abcde"` I've made the decision that the `--qualifier` parameter takes precedent over the `cdk.json` context if they are both set. --- .../lib/api/bootstrap/bootstrap-props.ts | 1 - packages/aws-cdk/lib/cli.ts | 2 +- packages/aws-cdk/test/cdk-toolkit.test.ts | 25 ++++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk/lib/api/bootstrap/bootstrap-props.ts b/packages/aws-cdk/lib/api/bootstrap/bootstrap-props.ts index 95661a0bd96b0..b575acb50fc78 100644 --- a/packages/aws-cdk/lib/api/bootstrap/bootstrap-props.ts +++ b/packages/aws-cdk/lib/api/bootstrap/bootstrap-props.ts @@ -129,5 +129,4 @@ export interface BootstrappingParameters { * @default - No value, optional argument */ readonly customPermissionsBoundary?: string; - } diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index ac7be73f2f019..f63c7cbf21eef 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -547,7 +547,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { let mockForEnvironment = jest.fn(); let mockCloudExecutable: MockCloudExecutable; beforeEach(() => { - template = { Resources: { Func: { @@ -394,6 +394,29 @@ describe('readCurrentTemplate', () => { }); }); +describe('bootstrap', () => { + test('accepts qualifier from context', async () => { + // GIVEN + const toolkit = defaultToolkitSetup(); + const configuration = new Configuration(); + configuration.context.set('@aws-cdk/core:bootstrapQualifier', 'abcde'); + + // WHEN + await toolkit.bootstrap(['aws://56789/south-pole'], bootstrapper, { + parameters: { + qualifier: configuration.context.get('@aws-cdk/core:bootstrapQualifier'), + }, + }); + + // THEN + expect(bootstrapper.bootstrapEnvironment).toHaveBeenCalledWith(expect.anything(), expect.anything(), { + parameters: { + qualifier: 'abcde', + }, + }); + }); +}); + describe('deploy', () => { test('fails when no valid stack names are given', async () => { // GIVEN