Created
March 14, 2021 19:04
-
-
Save yukiarrr/ca846d599d166c750bff5e8c8ac986f8 to your computer and use it in GitHub Desktop.
Check NestedStack diffs
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
| #!/bin/bash -e | |
| cdk synth > /dev/null | |
| color=${1:-'--color'} | |
| for stack_name in ${YOUR_PARENT_STACK_NAMES}; do | |
| resources=$(aws cloudformation list-stack-resources --stack-name ${stack_name}) | |
| length=$(echo ${resources} | jq '.StackResourceSummaries | length') | |
| for i in $(seq 0 $(expr ${length} - 1)); do | |
| summaries=$(echo ${resources} | jq ".StackResourceSummaries[${i}]") | |
| [ "$(echo ${summaries} | jq -r '.ResourceType')" != 'AWS::CloudFormation::Stack' ] && continue | |
| aws cloudformation get-template --stack-name $(echo ${summaries} | jq -r '.PhysicalResourceId') | jq '.TemplateBody' > template.json | |
| resource_id=$(echo ${summaries} | jq -r '.LogicalResourceId') | |
| stack_id=$(echo ${resource_id} | sed -e 's/NestedStack.*//') | |
| file=$(find . -name "${stack_name}${stack_id}*.nested.template.json") | |
| diff=$(json-diff ${color} template.json ${file} || true) | |
| [ "${diff}" ] || continue | |
| echo '------------------------------------------------------------------' | |
| echo ${resource_id} | |
| echo '------------------------------------------------------------------' | |
| echo -e "${diff}" | |
| done | |
| done | |
| rm -f template.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the inspiration! Did have a need for a Python version.