Skip to content

Commit bb50f97

Browse files
authored
fix(CLI): cdk diff is not clear enough about using read-only change sets (#28741)
Updates the messaging from diff when creating a changeset to clarify that the changeset will not be deployed. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4d7374e commit bb50f97

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/aws-cdk/lib/api/util/cloudformation.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ export async function createDiffChangeSet(options: PrepareChangeSetOptions): Pro
315315
for (const resource of Object.values((options.stack.template.Resources ?? {}))) {
316316
if ((resource as any).Type === 'AWS::CloudFormation::Stack') {
317317
// eslint-disable-next-line no-console
318-
debug('This stack contains one or more nested stacks, falling back to no change set diff...');
318+
debug('This stack contains one or more nested stacks, falling back to template-only diff...');
319319

320-
return undefined;
320+
//return undefined;
321321
}
322322
}
323323

@@ -337,7 +337,7 @@ async function uploadBodyParameterAndCreateChangeSet(options: PrepareChangeSetOp
337337
const cfn = preparedSdk.stackSdk.cloudFormation();
338338
const exists = (await CloudFormationStack.lookup(cfn, options.stack.stackName, false)).exists;
339339

340-
options.stream.write('Creating a change set, this may take a while...\n');
340+
options.stream.write('Hold on while we create a read-only change set to get a diff with accurate replacement information (use --no-change-set to use a less accurate but faster template-only diff)\n');
341341
return await createChangeSet({
342342
cfn,
343343
changeSetName: 'cdk-diff-change-set',
@@ -349,8 +349,8 @@ async function uploadBodyParameterAndCreateChangeSet(options: PrepareChangeSetOp
349349
parameters: options.parameters,
350350
});
351351
} catch (e: any) {
352-
// eslint-disable-next-line no-console
353-
console.error(`Failed to create change set with error: '${e.message}', falling back to no change-set diff`);
352+
debug(e.message);
353+
options.stream.write('Could not create a change set, will base the diff on template differences (run again with -v to see the reason)\n');
354354

355355
return undefined;
356356
}

packages/aws-cdk/test/diff.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ Resources
350350
const plainTextOutput = buffer.data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '')
351351
.replace(/[ \t]+$/mg, '');
352352
expect(plainTextOutput.trim()).toEqual(`Stack Parent
353+
Could not create a change set, will base the diff on template differences (run again with -v to see the reason)
353354
Resources
354355
[~] AWS::CloudFormation::Stack AdditionChild
355356
└─ [~] Resources

0 commit comments

Comments
 (0)