feat(cli): write cdk diff as machine-readable JSON to a file with --json-file - #1899
Draft
9pace wants to merge 1 commit into
Draft
feat(cli): write cdk diff as machine-readable JSON to a file with --json-file#18999pace wants to merge 1 commit into
9pace wants to merge 1 commit into
Conversation
…son-file Adds a '--json-file <path>' option to 'cdk diff' that writes the computed diff as a JSON document to the given path, while leaving the console output unchanged. The file maps each selected stack to its structural template diff (per-property old/new values with change impact), plus the IAM policy changes and security group rule changes already computed by @aws-cdk/cloudformation-diff, serialized by a new templateDiffToJson() function in that package.
9pace
force-pushed
the
feat/diff-json-output
branch
from
August 25, 2026 18:28
2b4762d to
d0c221d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
--json-file <path>option tocdk diffthat writes the computed diff as a machine-readable JSON document to the given path, while leaving the console output unchanged. This lets tooling consume diffs — e.g. review automation attaching evidence of what a change does to the synthesized templates — without scraping the formatted console output. Related to aws/aws-cdk#679.WILL_REPLACE, ...), plusiamChanges(statement/managed-policy additions and removals) andsecurityGroupChanges, and apermissionsBroadenedflag--fail) is unchangedDesign decisions:
templateDiffToJson()) lives in@aws-cdk/cloudformation-diff, which owns theTemplateDiffmodel and already had machine-readable serializers for the IAM scrutiny data and security group changes — this composes them and adds the structural part, reading the public getters into plain JSON (aTemplateDiffis a graph of class instances whose derived values are getters, so it cannot be stringified directly)CdkToolkit.diff(), whereDiffFormatteralready caches the structuredTemplateDiffper stack; serialization happens after formatting so the JSON reflects the same--strictfiltering as the console output--json-filerequires its argument:difftakes a variadicSTACKSpositional, so an optional-value flag would silently swallow a stack name as a filename (same reasondeploy --outputs-filerequires one)--security-onlyand--quiet; a file write keeps diff's behavior identical and is what automation needs. Can be added later without breaking this contract{ "type": "unparseable", "repr": "..." }rather than dropped (documented in the README)Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license