-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-cf-upsert.sh
22 lines (19 loc) · 940 Bytes
/
aws-cf-upsert.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash
args=("${@}")
stackName=${args[0]}
templateFileLocation=${args[1]}
parameters=("${args[@]:2}")
stackStatus=$(aws cloudformation describe-stacks --stack-name "${stackName}")
if [[ ${stackStatus} ]];
then
## 2>&1 redirect cloud formation error to standard console (https://www.brianstorti.com/understanding-shell-script-idiom-redirect/)
updateStatus=$(aws cloudformation update-stack --template-body file://"${templateFileLocation}" --stack-name "${stackName}" "${parameters[@]}" 2>&1)
## Skip waiting if no updates to watch for
if [[ ${updateStatus} != *"No updates are to be performed"* ]];
then
aws cloudformation wait stack-update-complete --stack-name "${stackName}"
fi
else
aws cloudformation create-stack --template-body file://"${templateFileLocation}" --stack-name "${stackName}" "${parameters[@]}"
aws cloudformation wait stack-create-complete --stack-name "${stackName}"
fi