-
Notifications
You must be signed in to change notification settings - Fork 11
/
deploy.sh
executable file
·62 lines (52 loc) · 2.17 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
#!/bin/bash
set -e
echo -e "\n\e[34m╔══════════════════════════════════╗"
echo -e "║\e[33m Deploy Management Infra 🚀\e[34m ║"
echo -e "║\e[32m Terraform Script\e[34m ║"
echo -e "╚══════════════════════════════════╝"
echo -e "\n\e[34m»»» ✅ \e[96mChecking pre-reqs\e[0m..."
# Load env vars from .env file
if [ ! -f ".env" ]; then
echo -e "\e[31m»»» 💥 Unable to find .env file, please create file and try again!"
exit
else
echo -e "\n\e[34m»»» 🧩 \e[96mLoading environmental variables\e[0m..."
export $(egrep -v '^#' ".env" | xargs)
fi
az > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\e[31m»»» ⚠️ Azure CLI is not installed! 😥 Please go to http://aka.ms/cli to set it up"
exit
fi
terraform version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\e[31m»»» ⚠️ Terraform is not installed! 😥 Please go to https://www.terraform.io/downloads.html to set it up"
exit
fi
export SUB_NAME=$(az account show --query name -o tsv)
if [[ -z $SUB_NAME ]]; then
echo -e "\n\e[31m»»» ⚠️ You are not logged in to Azure!"
exit
fi
export TENANT_ID=$(az account show --query tenantId -o tsv)
echo -e "\e[34m»»» 🔨 \e[96mAzure details from logged on user \e[0m"
echo -e "\e[34m»»» • \e[96mSubscription: \e[33m$SUB_NAME\e[0m"
echo -e "\e[34m»»» • \e[96mTenant: \e[33m$TENANT_ID\e[0m\n"
read -p " - Are these details correct, do you want to continue (y/n)? " answer
case ${answer:0:1} in
y|Y )
;;
* )
echo -e "\e[31m»»» 😲 Deployment canceled\e[0m\n"
exit
;;
esac
echo -e "\n\e[34m»»» ✨ \e[96mTerraform init\e[0m..."
terraform init -input=false -backend=true -reconfigure \
-backend-config="resource_group_name=$TF_VAR_mgmt_res_group" \
-backend-config="storage_account_name=$TF_VAR_state_storage" \
-backend-config="container_name=$TF_VAR_state_container"
echo -e "\n\e[34m»»» 📜 \e[96mTerraform plan\e[0m...\n"
terraform plan
echo -e "\n\e[34m»»» 🚀 \e[96mTerraform apply\e[0m...\n"
terraform apply -auto-approve