Skip to content

Commit

Permalink
fix(cli): bootstrap respects qualifier from cdk.json (#31410)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaizencc authored Sep 16, 2024
1 parent 1726abd commit 44134ad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/aws-cdk/lib/api/bootstrap/bootstrap-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,4 @@ export interface BootstrappingParameters {
* @default - No value, optional argument
*/
readonly customPermissionsBoundary?: string;

}
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
bucketName: configuration.settings.get(['toolkitBucket', 'bucketName']),
kmsKeyId: configuration.settings.get(['toolkitBucket', 'kmsKeyId']),
createCustomerMasterKey: args.bootstrapCustomerKey,
qualifier: args.qualifier,
qualifier: args.qualifier ?? configuration.context.get('@aws-cdk/core:bootstrapQualifier'),
publicAccessBlockConfiguration: args.publicAccessBlockConfiguration,
examplePermissionsBoundary: argv.examplePermissionsBoundary,
customPermissionsBoundary: argv.customPermissionsBoundary,
Expand Down
25 changes: 24 additions & 1 deletion packages/aws-cdk/test/cdk-toolkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { HotswapMode } from '../lib/api/hotswap/common';
import { Template } from '../lib/api/util/cloudformation';
import { CdkToolkit, Tag } from '../lib/cdk-toolkit';
import { RequireApproval } from '../lib/diff';
import { Configuration } from '../lib/settings';
import { flatten } from '../lib/util';

let cloudExecutable: MockCloudExecutable;
Expand Down Expand Up @@ -115,7 +116,6 @@ describe('readCurrentTemplate', () => {
let mockForEnvironment = jest.fn();
let mockCloudExecutable: MockCloudExecutable;
beforeEach(() => {

template = {
Resources: {
Func: {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 44134ad

Please sign in to comment.