-
Notifications
You must be signed in to change notification settings - Fork 4k
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(cdk): cdk diff --quiet
to print stack name when there is diffs
#30186
Changes from 1 commit
551b523
ae2bf0b
f312019
94fb996
ce831cc
da1305c
7a19200
dc6773d
6e198b3
9a27a9f
18ac849
0f251a2
22494e8
c735fad
2e46898
092fc2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import * as path from 'path'; | ||
import { format } from 'util'; | ||
import { fullDiff, TemplateDiff } from '@aws-cdk/cloudformation-diff'; | ||
import * as cxapi from '@aws-cdk/cx-api'; | ||
import * as chalk from 'chalk'; | ||
import * as chokidar from 'chokidar'; | ||
|
@@ -143,10 +144,6 @@ export class CdkToolkit { | |
} else { | ||
// Compare N stacks against deployed templates | ||
for (const stack of stacks.stackArtifacts) { | ||
if (!quiet) { | ||
stream.write(format('Stack %s\n', chalk.bold(stack.displayName))); | ||
} | ||
|
||
const templateWithNestedStacks = await this.props.deployments.readCurrentTemplateWithNestedStacks( | ||
stack, options.compareAgainstProcessedTemplate, | ||
); | ||
|
@@ -191,14 +188,21 @@ export class CdkToolkit { | |
} | ||
} | ||
|
||
const diff = options.securityOnly | ||
? fullDiff(currentTemplate, stack.template, changeSet) | ||
: fullDiff(currentTemplate, stack.template, changeSet, !!resourcesToImport); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not be calling |
||
if (!quiet || !diff.isEmpty) { | ||
stream.write(format('Stack %s\n', chalk.bold(stack.displayName))); | ||
} | ||
|
||
if (resourcesToImport) { | ||
stream.write('Parameters and rules created during migration do not affect resource configuration.\n'); | ||
} | ||
|
||
const stackCount = | ||
options.securityOnly | ||
? (numberFromBool(printSecurityDiff(currentTemplate, stack, RequireApproval.Broadening, changeSet))) | ||
: (printStackDiff(currentTemplate, stack, strict, contextLines, quiet, changeSet, !!resourcesToImport, stream, nestedStacks)); | ||
? (numberFromBool(printSecurityDiff(currentTemplate, stack, RequireApproval.Broadening, changeSet, diff))) | ||
: (printStackDiff(currentTemplate, stack, strict, contextLines, quiet, changeSet, !!resourcesToImport, stream, nestedStacks, diff)); | ||
|
||
diffs += stackCount; | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -393,15 +393,37 @@ describe('non-nested stacks', () => { | |||
|
||||
// WHEN | ||||
const exitCode = await toolkit.diff({ | ||||
stackNames: ['A', 'A'], | ||||
stackNames: ['D'], | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed a broken test. Originally, the test assumed there was no difference, but the specification
|
||||
stream: buffer, | ||||
fail: false, | ||||
quiet: true, | ||||
}); | ||||
|
||||
// THEN | ||||
const plainTextOutput = buffer.data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, ''); | ||||
expect(plainTextOutput).not.toContain('Stack D'); | ||||
expect(plainTextOutput).not.toContain('There were no differences'); | ||||
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 0'); | ||||
expect(exitCode).toBe(0); | ||||
}); | ||||
|
||||
test('when quiet mode is enabled, stacks with diffs should print stack name to stdout', async () => { | ||||
// GIVEN | ||||
const buffer = new StringWritable(); | ||||
|
||||
// WHEN | ||||
const exitCode = await toolkit.diff({ | ||||
stackNames: ['A'], | ||||
stream: buffer, | ||||
fail: false, | ||||
quiet: true, | ||||
}); | ||||
|
||||
// THEN | ||||
expect(buffer.data.trim()).not.toContain('Stack A'); | ||||
expect(buffer.data.trim()).not.toContain('There were no differences'); | ||||
const plainTextOutput = buffer.data.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, ''); | ||||
expect(plainTextOutput).toContain('Stack A'); | ||||
expect(plainTextOutput).not.toContain('There were no differences'); | ||||
expect(buffer.data.trim()).toContain('✨ Number of stacks with differences: 1'); | ||||
expect(exitCode).toBe(0); | ||||
}); | ||||
}); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous PR, it was commented that the stack name output should be done in the
printSecurityDiff
function, but I decided to write it this way because we think it is more user-friendly to write all messages after the stack name output.Please let me know if you have a better way to write it or if you have another opinion!
#28576 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should print all messages after the stack name output, so can we move all of those messages after the stack name output and move the stack name to
printSecurityDiff
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, can you explain which messages are unable to be moved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @comcalvi.
I think such an implementation is possible.
I have one question:
I forgot to mention that in the current code, the messages generated during the changeset creation are displayed before the stack name.
Is this acceptable?
To fix this issue, it is necessary to control the display of the stack name based on the presence of a diff when the
--quiet
flag is true.However, determining the diff requires creating a changeset (though there are cases where it is unnecessary), and messages are output during this process.
While it might be necessary to suppress these messages when the
--quiet
flag is true, debug messages are also output during the changeset creation process when the-v
flag is specified.We would need to allow cases where messages output during the changeset creation process appear before the stack name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, I am thinking of changing the
printStackDiff
function to look like thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no harm in creating the changeset before printing the stack name. Since we now need the changeset to determine the diff, I think that is what we must do.