-
Notifications
You must be signed in to change notification settings - Fork 4
/
apply.sh
executable file
·37 lines (29 loc) · 977 Bytes
/
apply.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
#!/bin/bash
set -e
ENVIRONMENT=$1
DIR_ABS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SYSTEM=$(basename $DIR_ABS)
if [ ! -f _$ENVIRONMENT/proposed.plan ]; then
echo "The planning file was not found. Please first run 'plan.sh' to generate a plan to apply."
exit 1
fi
if [ -z $ENVIRONMENT ]; then
echo "No environment set. Please use 'development', 'staging', 'testing' or 'production'"
exit 1
fi
if [ "$ENVIRONMENT" != development ] \
&& [ "$ENVIRONMENT" != testing ] \
&& [ "$ENVIRONMENT" != staging ] \
&& [ "$ENVIRONMENT" != production ]; then
echo "Incorrect value for environment. Please use 'development', 'staging', 'testing' or 'production'"
exit 1
fi
echo "Preparing to apply:"
echo "==================="
echo "System: ${SYSTEM}"
echo "Environment: _$ENVIRONMENT"
terraform apply \
_$ENVIRONMENT/proposed.plan
rm _$ENVIRONMENT/proposed.plan
rm -rf .terraform/terraform.tfstate
rm -rf .terraform/terraform.tfstate.backup