|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | +scriptdir=$(cd $(dirname $0) && pwd) |
| 4 | +source ${scriptdir}/common.bash |
| 5 | +# ---------------------------------------------------------- |
| 6 | +# this test verifies that deployment is skipped when the template did not |
| 7 | +# change, and that `--force` can be used to override this behavior. |
| 8 | + |
| 9 | +setup |
| 10 | + |
| 11 | +# we are using a stack with a nested stack because CFN will always attempt to |
| 12 | +# update a nested stack, which will allow us to verify that updates are actually |
| 13 | +# skipped unless --force is specified. |
| 14 | +stack_name="${STACK_NAME_PREFIX}-with-nested-stack" |
| 15 | + |
| 16 | +get_last_changeset() { |
| 17 | + aws cloudformation describe-stacks --stack-name ${stack_name} --query 'Stacks[0].ChangeSetId' |
| 18 | +} |
| 19 | + |
| 20 | +# deploy once |
| 21 | +echo "============================================================" |
| 22 | +echo " deploying stack" |
| 23 | +echo "============================================================" |
| 24 | +cdk deploy -v ${stack_name} |
| 25 | +changeset1=$(get_last_changeset) |
| 26 | +echo "changeset1=${changeset1}" |
| 27 | + |
| 28 | +echo "============================================================" |
| 29 | +echo " deploying the same stack again (no change)" |
| 30 | +echo "============================================================" |
| 31 | +cdk deploy -v ${stack_name} |
| 32 | +changeset2=$(get_last_changeset) |
| 33 | +if [ "${changeset2}" != "${changeset1}" ]; then |
| 34 | + echo "TEST FAILED: expected the 'cdk deploy' will skip deployment because the app did not change" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +echo "============================================================" |
| 39 | +echo " deploying the same stack again (no change, --force)" |
| 40 | +echo "============================================================" |
| 41 | +cdk deploy --force -v ${stack_name} |
| 42 | +changeset3=$(get_last_changeset) |
| 43 | +if [ "${changeset3}" == "${changeset1}" ]; then |
| 44 | + echo "TEST FAILED: expected --force to create a new changeset" |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +# destroy |
| 49 | +cdk destroy -f ${stack_name} |
| 50 | + |
| 51 | +echo "✅ success" |
0 commit comments