-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-stack
executable file
·68 lines (56 loc) · 1.89 KB
/
create-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
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
set -e
script_dir=$(cd "$(dirname "$0")" ; pwd -P)
create-update() {
pushd "${script_dir}" > /dev/null
project_name="${1}"
module_name="${2}"
aws_region="${3}"
for i in project_name module_name aws_region; do
if [ -z "!{i}" ]; then
echo "${i} not set. Usage <func: create-update> PROJECT_NAME MODULE_NAME AWS_REGION"
exit 1
fi
done
create-update-stack "${project_name}" "${module_name}" "${aws_region}"
popd > /dev/null
}
create-update-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 "Stack (${stack_name}) does not exist. Creating..."
aws cloudformation create-stack --stack-name "${project_name}-${module_name}-co2-tmp-s3-bucket" \
--template-body file://./template.yaml \
--capabilities CAPABILITY_NAMED_IAM \
--region ${aws_region} \
--parameters ParameterKey=ProjectName,ParameterValue=${project_name} ParameterKey=ModuleName,ParameterValue=${module_name}
fi
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
create-update ${project} ${module} ${region}
echo "View your Cloudformation Stack at https://${region}.console.aws.amazon.com/cloudformation/home?region=${region}#/stacks"