Skip to content
cdkd

cdkd diff: JSON output

cdkd diff --json prints the diff as JSON for a script or a CI job to read. The output is an array with one record per stack you selected. Progress messages are suppressed, so stdout holds only the JSON.

cdkd diff MyStack --json

# stacks with changes
cdkd diff --all --json | jq '.[] | select(.changes != []) | .stack'

The record for one stack

[
  {
    "stack": "MyStack",
    "region": "us-east-1",
    "changes": [
      {
        "logicalId": "ApiFunction",
        "changeType": "UPDATE",
        "resourceType": "AWS::Lambda::Function",
        "propertyChanges": [
          {
            "path": "Timeout",
            "oldValue": 3,
            "newValue": 30,
            "requiresReplacement": false
          }
        ]
      }
    ],
    "outputChanges": [],
    "unreadable": [],
    "unreadableContainers": [],
    "unreadableOrphans": [],
    "destructiveChanges": [],
    "children": []
  }
]

Every field at the top level of a record is always present, so a script can rely on the same set of keys in every run.

Field Holds
changes One entry per changed resource.
outputChanges One entry per changed stack output.
destructiveChanges The changes --fail-on=destructive fails on.
children One record per nested stack.
unreadable Resources in state the diff could not read.
unreadableContainers Whole parts of state the diff could not read.
unreadableOrphans Rollback leftovers in state the diff could not read.

The sections below describe each one.

changes

changes has one entry for each resource the deploy would create, update or delete. Resources that would not change are left out.

Every entry has logicalId, changeType and resourceType. The fields below appear only when they apply:

Field Present when
propertyChanges At least one property changes.
attributeChanges At least one attribute changes.
nestedChildHeal true on a nested stack the deploy updates only so that its own deploy fixes an SSM parameter name an older cdkd recorded with a leading /.
nestedStackTagsChanged true on a nested stack the deploy updates because its stack tags changed, so its resources get the new tags.
providerReplacement An UPDATE the deploy carries out by deleting the resource and creating it again; the value says why.
prefixRename An UPDATE that renames an IAM role or managed policy because the run's stack-name prefix setting derives its declared name in the other form: drops-prefix or adds-prefix. The deploy replaces it, creating the new one first.
ccApi The resource would go through the Cloud Control API.
movedTo A DELETE that cdkd refactor would keep: { "stackName", "logicalId" } of where the resource reappears.

ccApi is a list of strings. It is the JSON form of the [via CC API: ...] note in the text output.

propertyChanges

Each entry gives the property's path, its oldValue and newValue, and requiresReplacement. An entry flagged newValueKnownAfterDeploy also carries newValueTemplate.

The notes that the text output prints in square brackets appear here as flags. A flag is present and true on the lines that carry the note, and absent on all others.

Flag Note in the text output
replacementPropagated [replacement propagated]
inPlacePropagated [attribute propagated]
readProvenancePromoted (with inPlacePropagated) [read value moved upstream]
maskedExpressionChanged [masked input or expression changed]
newValueKnownAfterDeploy [reads a resource this deploy changes]

Three things to know when reading these entries:

  • On an entry with maskedExpressionChanged, oldValue and newValue are both ***.
  • On an entry with newValueKnownAfterDeploy, newValue was resolved against the resources as they are now. It still embeds the old physical ID, ARN or attribute of the resource this deploy changes, so it is not the value the deploy will write. newValueTemplate holds the template value the text output prints instead.
  • On a propagated entry, requiresReplacement: true means the resource may be replaced. It is not a verdict, because the deploy decides once it knows the new value.

outputChanges

Each entry describes one changed stack output:

{
  "name": "BucketArn",
  "changeType": "MODIFY",
  "oldValue": "arn:aws:s3:::old-bucket",
  "newValue": "arn:aws:s3:::my-bucket",
  "export": false
}
Field Holds
name The output's name.
changeType ADD, MODIFY or REMOVE.
oldValue The value in state. Absent on an ADD.
newValue The value the deploy would publish. Absent on a REMOVE.
export Whether the row is an export name.
oldValueRedacted true when the old value is withheld.
nameRedacted true when the name is masked or withheld.

cdkd withholds an old value, or masks a name, when it may hold a secret. In that case oldValue is replaced by oldValueRedacted: true. A name that holds a secret is masked or withheld and carries nameRedacted: true, and two withheld rows can then have the same name. The reasons are under cdkd diff: secrets and NoEcho values.

destructiveChanges

Each entry is one change that --fail-on=destructive fails on. It has logicalId, resourceType, impact, constructPath when state records one, movedTo on a WILL_DESTROY removal cdkd refactor would keep, earlyDelete on a WILL_REPLACE whose old resource is deleted before the deploy succeeds, and oldCopy: true on a WILL_DESTROY that is no template change but the old resource an earlier deploy replaced and kept in state, which the deploy deletes (its logicalId is the replaced resource's).

earlyDelete The old resource is deleted
before-create Before its replacement is created (an SNS subscription its provider re-creates)
during-deploy Before the deploy succeeds (a renamed Route 53 record set, in the batch that creates the new one)
recreate Before its replacement is created, unless the replacement takes another name (a --recreate-via-* target; the deploy's approval prompt only)

A failed deploy's rollback re-creates such a resource from its recorded properties only. See --fail-on.

impact Text output
WILL_REPLACE will be replaced
MAY_REPLACE may be replaced
WILL_DESTROY will be destroyed
WILL_ORPHAN will be orphaned

What each impact means is under --fail-on.

children

children holds one record per nested stack, in the same shape as the record for a top-level stack. It is filled only with --recursive or --fail-on=destructive, and is empty otherwise.

The three unreadable fields

These fields are empty unless the state record is damaged. When any of them holds an entry, changes does not show everything, because the diff treated the damaged part of state as empty.

Field Holds
unreadable The logical ID of each resource entry the diff dropped.
unreadableContainers "resources" or "orphans".
unreadableOrphans One element per unreadable rollback leftover.

unreadableContainers lists "resources" when the whole map of resources is not an object, and "orphans" when the list of rollback leftovers is not a list. Each element of unreadableOrphans is the leftover's logicalId, or null when the record has none.

A rollback leftover is a resource a failed deploy left in AWS, which state remembers so that the next deploy can adopt it. What the diff does with each kind of damage is under cdkd diff: incomplete or malformed state.

Control characters in the payload

Control, format and line-separator characters in the payload are written as \uXXXX escapes. A JSON parser turns them back into the same values, and printing the raw payload cannot run a terminal control sequence.

Last updated: