-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·54 lines (44 loc) · 1011 Bytes
/
deploy.sh
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
#!/usr/bin/env bash
set -euo pipefail
function usage {
echo "Usage: $0 <env>" >&2
exit 1
}
service=do-foundations
[[ $# -ge 1 ]] || usage
environment=$1
shift
echo "Deploying $service-$environment... " >&2
echo >&2
eval "$(./terraform-env.sh "$service" "$environment")"
# shellcheck disable=SC2154
echo -n "- Creating $stateBucket... " >&2
if ! result="$(aws s3api create-bucket --bucket "$stateBucket" 2>&1)" ; then
if [[ "$result" =~ BucketAlreadyExists ]]; then
: # continue
else
echo 'failed' >&2
echo >&2
echo "$result" >&2
exit 1
fi
fi
echo 'done' >&2
echo -n "- Initialising terraform... " >&2
if ! result="$(terraform init -input=false -lockfile=readonly)"; then
echo 'failed' >&2
echo >&2
echo "$result" >&2
exit 1
fi
echo 'done' >&2
echo -n "- Running terraform apply... " >&2
if ! result="$(terraform apply -auto-approve -input=false)"; then
echo 'failed' >&2
echo >&2
echo "$result" >&2
exit 1
fi
echo 'done' >&2
echo >&2
echo 'Deployment complete' >&2