Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(core): cdk diff on large templates fails when passing in toolkitStackName and qualifier #31636

Merged
7 changes: 6 additions & 1 deletion packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ interface CommonCdkBootstrapCommandOptions {
* @default - none
*/
readonly tags?: string;

/**
* @default - the default CDK qualifier
*/
readonly qualifier?: string;
}

export interface CdkLegacyBootstrapCommandOptions extends CommonCdkBootstrapCommandOptions {
Expand Down Expand Up @@ -423,7 +428,7 @@ export class TestFixture extends ShellHelper {
if (options.bootstrapBucketName) {
args.push('--bootstrap-bucket-name', options.bootstrapBucketName);
}
args.push('--qualifier', this.qualifier);
args.push('--qualifier', options.qualifier ?? this.qualifier);
if (options.cfnExecutionPolicy) {
args.push('--cloudformation-execution-policies', options.cfnExecutionPolicy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,48 @@ integTest(
}),
);

integTest('cdk diff with large changeset and custom toolkit stack name and qualifier does not fail', withoutBootstrap(async (fixture) => {
// Bootstrapping with custom toolkit stack name and qualifier
const qualifier = 'abc1234';
const toolkitStackName = 'custom-stack';
const bootstrapBucketName = 'cdk-abc1234-assets-587443617500-us-east-1';
await fixture.cdkBootstrapModern({
verbose: true,
toolkitStackName: toolkitStackName,
qualifier: qualifier,
bootstrapBucketName: bootstrapBucketName,
});

// Deploying small initial stack with only ane IAM role
await fixture.cdkDeploy('iam-roles', {
modEnv: {
NUMBER_OF_ROLES: '1',
},
options: [
'--context', `bootstrapBucket=${bootstrapBucketName}`,
'--toolkit-stack-name', toolkitStackName,
'--context', `@aws-cdk/core:bootstrapQualifier=${qualifier}`,
],
});

// WHEN - adding 200 roles to the same stack to create a large diff
const diff = await fixture.cdk(['diff', fixture.fullStackName('iam-roles')], {
verbose: true,
modEnv: {
NUMBER_OF_ROLES: '200',
},
options: [
'--context', `bootstrapBucket=${bootstrapBucketName}`,
'--toolkit-stack-name', toolkitStackName,
'--context', `@aws-cdk/core:bootstrapQualifier=${qualifier}`,
],
});

// Assert that the CLI assumes the file publishing role:
expect(diff).toMatch(/Assuming role .*file-publishing-role/);
expect(diff).toContain('success: Published');
}));

integTest(
'cdk diff --security-only successfully outputs sso-permission-set-without-managed-policy information',
withDefaultFixture(async (fixture) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk/lib/api/util/cloudformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export type PrepareChangeSetOptions = {
sdkProvider: SdkProvider;
stream: NodeJS.WritableStream;
parameters: { [name: string]: string | undefined };
toolkitStackName?: string;
resourcesToImport?: ResourcesToImport;
}

Expand Down Expand Up @@ -375,9 +376,11 @@ async function uploadBodyParameterAndCreateChangeSet(options: PrepareChangeSetOp
for (const entry of file_entries) {
await options.deployments.buildSingleAsset(artifact, assetManifest, entry, {
stack: options.stack,
toolkitStackName: options.toolkitStackName,
});
await options.deployments.publishSingleAsset(assetManifest, entry, {
stack: options.stack,
toolkitStackName: options.toolkitStackName,
});
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class CdkToolkit {
parameters: Object.assign({}, parameterMap['*'], parameterMap[stack.stackName]),
resourcesToImport,
stream,
toolkitStackName: options.toolkitStackName,
});
} else {
debug(`the stack '${stack.stackName}' has not been deployed to CloudFormation or describeStacks call failed, skipping changeset creation.`);
Expand Down Expand Up @@ -1106,6 +1107,13 @@ export interface DiffOptions {
*/
stackNames: string[];

/**
* Name of the toolkit stack, if not the default name
*
* @default 'CDKToolkit'
*/
readonly toolkitStackName?: string;

/**
* Only select the given stack
*
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
compareAgainstProcessedTemplate: args.processed,
quiet: args.quiet,
changeSet: args['change-set'],
toolkitStackName: toolkitStackName,
});

case 'bootstrap':
Expand Down
Loading