#!/bin/bash
WAIT_TYPE=$1
stack=$2
region=$3
changeset=$4
if WAIT_TYPE='changeset'; then
echo "Check $WAIT_TYPE Status..."
stackStatus=($(aws cloudformation describe-change-set --region $region --stack-name $stack --change-set-name $changeset --query Status --output text))
until
[ "$stackStatus" = "CREATE_COMPLETE" ] ||
[ "$stackStatus" = "CREATE_FAILED" ] ||
[ "$stackStatus" = "DELETE_COMPLETE" ] ||
[ "$stackStatus" = "DELETE_FAILED" ] ||
[ "$stackStatus" = "ROLLBACK_COMPLETE" ] ||
[ "$stackStatus" = "ROLLBACK_FAILED" ] ||
[ "$stackStatus" = "UPDATE_COMPLETE" ] ||
[ "$stackStatus" = "UPDATE_ROLLBACK_COMPLETE" ] ||
[ "$stackStatus" = "UPDATE_ROLLBACK_FAILED" ]
echo $stackStatus
do
ChangeSetId=($(aws cloudformation describe-change-set --region $region --stack-name $stack --change-set-name $changeset --query ChangeSetId --output text))
echo "ChangeSet $stackStatus: $ChangeSetId ..."
done
fi
if WAIT_TYPE='stack'; then
echo "Check $WAIT_TYPE Status..."
stackStatus=($(aws cloudformation describe-stacks --region $region --stack-name $stack --query Stacks[0].StackStatus --output text))
until
[ "$stackStatus" = "CREATE_COMPLETE" ] ||
[ "$stackStatus" = "CREATE_FAILED" ] ||
[ "$stackStatus" = "DELETE_COMPLETE" ] ||
[ "$stackStatus" = "DELETE_FAILED" ] ||
[ "$stackStatus" = "ROLLBACK_COMPLETE" ] ||
[ "$stackStatus" = "ROLLBACK_FAILED" ] ||
[ "$stackStatus" = "UPDATE_COMPLETE" ] ||
[ "$stackStatus" = "UPDATE_ROLLBACK_COMPLETE" ] ||
[ "$stackStatus" = "UPDATE_ROLLBACK_FAILED" ]
echo $stackStatus
do
eventId=($(aws cloudformation describe-stack-events --region $region --stack $stack --query StackEvents[0].PhysicalResourceId --output text))
if [ "$eventId" != "$lastEventId" ]; then
echo "Deploying/updating: $eventId"
lastEventId=$eventId
fi
sleep 3
stackStatus=($(aws cloudformation describe-stacks --region $region --stack-name $stack --query Stacks[0].StackStatus --output text))
echo "Stack $stackStatus: $eventId ..."
done
echo "Stack Status: $stackStatus"
if [ "$stackStatus" != "CREATE_COMPLETE" ] && [ "$stackStatus" != "UPDATE_COMPLETE" ] && [ "$stackStatus" != "DELETE_COMPLETE" ] && [ ! -z "$stackStatus" ]; then
exit 1
fi
fi
No comments:
Post a Comment