-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-or-update
executable file
·50 lines (37 loc) · 1.32 KB
/
create-or-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
echo "Checking if stack exists ..."
if ! aws cloudformation describe-stacks --region us-west-2 --stack-name $1 ; then
echo -e "\nStack does not exist, creating ..."
aws cloudformation create-stack \
--stack-name $1 \
--template-body file://$2 \
--parameters file://$3 \
--region=us-west-2 \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND
echo "Waiting for stack to be created ..."
aws cloudformation wait stack-create-complete --stack-name $1 --region=us-west-2
else
echo -e "\nStack exists, attempting update ..."
set +e
update_output=$( aws cloudformation update-stack \
--stack-name $1 \
--template-body file://$2 \
--parameters file://$3 \
--region=us-west-2 \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND 2>&1)
status=$?
set -e
echo "$update_output"
if [ $status -ne 0 ] ; then
# Don't fail for no-op update
if [[ $update_output == *"ValidationError"* && $update_output == *"No updates"* ]] ; then
echo -e "\nFinished create/update - no updates to be performed"
exit 0
else
exit $status
fi
fi
echo "Waiting for stack update to complete ..."
aws cloudformation wait stack-update-complete --stack-name $1 --region=us-west-2
fi
echo "Finished create/update successfully!"