-
Notifications
You must be signed in to change notification settings - Fork 4
/
plan.sh
executable file
·44 lines (35 loc) · 1.1 KB
/
plan.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
#!/bin/bash
set -e
ENVIRONMENT=$1
DIR_ABS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SYSTEM=$(basename $DIR_ABS)
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
if ! [ -L "common.tf" ]; then
echo "Missing common.tf symlink, creating..."
ln -s ../common.tf common.tf
echo "Symlink to common.tf created."
fi
echo "Preparing the plan:"
echo "==================="
echo "System: ${SYSTEM}"
echo "Environment: _$ENVIRONMENT"
rm -rf .terraform/terraform.tfstate
mkdir -p .terraform
cp _$ENVIRONMENT/terraform.tfstate ./.terraform/
terraform fmt ../
terraform get
terraform plan \
-var "environment=$ENVIRONMENT" \
-var-file="../env.$ENVIRONMENT.tfvars" \
-var-file=_$ENVIRONMENT/environment.tfvars \
-out=_$ENVIRONMENT/proposed.plan