-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-stack
executable file
·59 lines (48 loc) · 1.53 KB
/
delete-stack
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
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
set -e
script_dir=$(cd "$(dirname "$0")" ; pwd -P)
delete-stack() {
project_name="${1}"
module_name="${2}"
aws_region="${3}"
pushd "${script_dir}" > /dev/null
stack_name="${project_name}-${module_name}-co2-tmp-s3-bucket"
if [[ $(aws cloudformation describe-stacks --stack-name "${stack_name}" --region "${aws_region}") ]]; then
echo "Emptying bucket s3://${project_name}-${module_name}..."
aws s3 rm "s3://${project_name}-${module_name}" --recursive
echo "Stack (${stack_name}) exists. Deleting..."
aws cloudformation delete-stack --stack-name "${stack_name}" \
--stack-name "${stack_name}" \
--region "${aws_region}"
else
echo "Stack (${stack_name}) does not exist. Nothing to do here!"
fi
until $(aws cloudformation describe-stacks --stack-name "${stack_name}" --region "${aws_region}" 2>&1 | grep -q "${stack_name} does not exist")
do
echo "Deleting..."
sleep 10
done
popd > /dev/null
}
usage() { echo "Usage: $0 [-p <project name: string>] [-m <module name: string>] [-r <aws region: string>]" 1>&2; exit 1; }
while getopts ":p:m:r:" o; do
case "${o}" in
p)
project=${OPTARG}
;;
m)
module=${OPTARG}
;;
r)
region=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${project}" ] || [ -z "${module}" ] || [ -z "${region}" ]; then
usage
fi
delete-stack "${project}" "${module}" "${region}"