Skip to content

Commit

Permalink
fix(CLI): cdk diff is not clear enough about using read-only change…
Browse files Browse the repository at this point in the history
… sets (aws#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*
  • Loading branch information
comcalvi committed Jan 18, 2024
1 parent 4d7374e commit bb50f97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/aws-cdk/lib/api/util/cloudformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ export async function createDiffChangeSet(options: PrepareChangeSetOptions): Pro
for (const resource of Object.values((options.stack.template.Resources ?? {}))) {
if ((resource as any).Type === 'AWS::CloudFormation::Stack') {
// eslint-disable-next-line no-console
debug('This stack contains one or more nested stacks, falling back to no change set diff...');
debug('This stack contains one or more nested stacks, falling back to template-only diff...');

return undefined;
//return undefined;
}
}

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

options.stream.write('Creating a change set, this may take a while...\n');
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');
return await createChangeSet({
cfn,
changeSetName: 'cdk-diff-change-set',
Expand All @@ -349,8 +349,8 @@ async function uploadBodyParameterAndCreateChangeSet(options: PrepareChangeSetOp
parameters: options.parameters,
});
} catch (e: any) {
// eslint-disable-next-line no-console
console.error(`Failed to create change set with error: '${e.message}', falling back to no change-set diff`);
debug(e.message);
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');

return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk/test/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ Resources
const plainTextOutput = buffer.data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '')
.replace(/[ \t]+$/mg, '');
expect(plainTextOutput.trim()).toEqual(`Stack Parent
Could not create a change set, will base the diff on template differences (run again with -v to see the reason)
Resources
[~] AWS::CloudFormation::Stack AdditionChild
└─ [~] Resources
Expand Down

0 comments on commit bb50f97

Please sign in to comment.