Description
Describe the feature
When running the diff
action, the result lacks information about the number of stacks with changes, despite the toolkit previously providing this information via IoHost.
The CDK CLI uses its formatter to calculate the diff, but other programmatic implementations can benefit from this precalculated info.
At https://github.com/aws/aws-cdk-cli/blob/52457cfc25dce58e8b3d1da8ff20c87cfd336034/packages/%40aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts#L368C1-L371C8 we have the diff span end, which contains the formatted diff, but could also include the number of stacks with diffs. To figure out the number of stacks with diffs, you'd have to parse the log span message or re-do the whole calculation yourself.
I think we can benefit from:
- Providing access to the currently private https://github.com/aws/aws-cdk-cli/blob/main/packages/%40aws-cdk/toolkit-lib/lib/api/io/private/messages.ts#L527
IO
andSPAN
enums, which would allow us to extract this info from the IoHost messages without having to hardcode the various IO codes (likeCDK_TOOLKIT_I4001
) in the host code. - Exposing the number of stacks with differences in the log span
- Exposing the number of changed stacks info also as part of the
diff
function result, maybe as a boolean inside each stack result object (an overallhasChanges: true/false
for each stack)
Diff log:
// Here we have the stack changes count, but it is provided in the message string only
[03:39:00.242] INFO (CDK/44572): ✨ Number of stacks with differences: 0
code: "CDK_TOOLKIT_I4001"
data: {
"duration": 9383,
"formattedSecurityDiff": "",
"formattedStackDiff": "Stack \u001b[1mExample-Stack\u001b[22m\n\u001b[32mThere were no differences\u001b[39m\n\u001b[32m\u001b[39m"
}
span: "055e1fcb-9f57-4f7f-b88b-e830883a8c1b"
action: "diff"
// This is the result of the `.diff` command
// This needs to be re-parsed to figure out if there have been diffs
[03:39:00.243] INFO (44572): Diff result
diffResult: {
"Example-Stack": {
"conditions": {
"diffs": {}
},
"mappings": {
"diffs": {}
},
"metadata": {
"diffs": {}
},
"outputs": {
"diffs": {}
},
"parameters": {
"diffs": {}
},
"resources": {
"diffs": {}
},
"unknown": {
"diffs": {}
},
"iamChanges": {
"statements": {
"additions": [],
"removals": [],
"oldElements": [],
"newElements": []
},
"managedPolicies": {
"additions": [],
"removals": [],
"oldElements": [],
"newElements": []
},
"ssoPermissionSets": {
"additions": [],
"removals": [],
"oldElements": [],
"newElements": []
},
"ssoAssignments": {
"additions": [],
"removals": [],
"oldElements": [],
"newElements": []
},
"ssoInstanceACAConfigs": {
"additions": [],
"removals": [],
"oldElements": [],
"newElements": []
}
},
"securityGroupChanges": {
"ingress": {
"additions": [],
"removals": [],
"oldElements": [],
"newElements": []
},
"egress": {
"additions": [],
"removals": [],
"oldElements": [],
"newElements": []
}
}
}
}
Use Case
When using the toolkit-lib programmatically, I need a way to tell the user whether we have differences or not in the stacks. I'd like to do that with already generated info instead of having to do the parsing again.
Proposed Solution
No response
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
CDK version used
2.195.0
Environment details (OS name and version, etc.)
Windows 11 64bit