This repository has been archived by the owner on May 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.sh
executable file
·64 lines (52 loc) · 1.76 KB
/
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
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# To run the deployment:
# Initialise the remote state first with ./deploy.sh
# ./deploy.sh [plan|apply|destroy]
# capture the current path
current_path=$(pwd)
tf_command=$1
function initialize_state {
echo 'Initializing remote terraform state'
cd tfstate
terraform init
terraform apply -auto-approve
cd "${current_path}"
}
function deploy_blueprint {
cd tfstate
storage_account_name=$(terraform output storage_account_name)
echo ${storage_account_name}
access_key=$(terraform output access_key)
container=$(terraform output container)
prefix=$(terraform output prefix)
tf_name="${prefix}.tfstate"
cd "${current_path}"
pwd
terraform init \
-reconfigure \
-backend=true \
-lock=false \
-backend-config storage_account_name=${storage_account_name} \
-backend-config container_name=${container} \
-backend-config access_key=${access_key} \
-backend-config key=${tf_name}
terraform ${tf_command} \
-var prefix=${prefix}
}
# Initialise storage account to store remote terraform state
if [[ -z "$2" ]]; then
initialize_state
fi
if [[ -n "${tf_command}" ]]; then
echo ''
echo "Deploying blueprint with terraform command '${tf_command}'"
echo ''
deploy_blueprint
else
echo ''
echo 'You have to run at least once ./deploy.sh with no parameters to setup the remote state.'
echo 'To deploy a bluepring run the terraform command [plan|apply|destroy]'
echo './deploy.sh plan'
echo ''
echo 'Note: the script does the terraform init for you.'
fi