awslabs / landing-zone-accelerator-on-aws

Deploy a multi-account cloud foundation to support highly-regulated workloads and complex compliance requirements.
https://aws.amazon.com/solutions/implementations/landing-zone-accelerator-on-aws/
Apache License 2.0
542 stars 433 forks source link

JSON parse error in`printStackDiff` leading to malformed diffs #597

Open k7k0 opened 1 week ago

k7k0 commented 1 week ago

Describe the bug When running a stack diff, the printStackDiff function is doing a JSON.stringify of newTemplate which is the template path, not the contents. Leading to diffs like this:

Stack: AWSAccelerator-NetworkAssociationsGwlbStack-<account>-<region>
Other Changes
[+] Unknown 270: l
[+] Unknown 271: a
[+] Unknown 272: t
[+] Unknown 273: e
[+] Unknown 274: .
[+] Unknown 275: j
[+] Unknown 276: s
[+] Unknown 277: o
[+] Unknown 278: n
[~] Unknown 266: j to t
[~] Unknown 267: s to e
[~] Unknown 268: o to m
[~] Unknown 269: n to 

instead it should do JSON.stringify(readTemplate(newTemplate)) to stringify the file contents and get the correct mangled version.

To Reproduce Synth and diff a stage having differenceCount bigger than the number of letters of the .json path length. For example, add a new region and a VPC, then

yarn ts-node --transpile-only cdk.ts --require-approval never --partition aws --stage network-associations --config-dir <config- dir> synth
yarn ts-node --transpile-only cdk.ts --require-approval never --partition aws --stage network-associations --config-dir <config-dir> diff

Expected behavior

Stack: AWSAccelerator-NetworkAssociationsGwlbStack-<account>-<region>
Template
[+] Description Description: (SO0199-networkgwlb) Landing Zone Accelerator on AWS. Version 1.9.2.

Parameters
[+] Parameter ###
....

Resources
[+] AWS::SSM::Parameter ###
[+] AWS::SSM::Parameter ###

Please complete the following information about the solution:

richardkeit commented 1 week ago

Smart @k7k0!

Related issue:

k7k0 commented 1 week ago

it looks like a regression introduced while upgrading to CDK 2.148.0.

image

readTemplate should be used for the fullDiff on next line as well