-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·136 lines (123 loc) · 3.72 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
echo "
##############################################################################################################
#
# Deployment of a Single FortiGate VM
#
##############################################################################################################
"
# Stop on error
set +e
if [ -z "$DEPLOY_LOCATION" ]
then
# Input location
echo -n "Enter location (e.g. eastus2): "
stty_orig=`stty -g` # save original terminal setting.
read location # read the location
stty $stty_orig # restore terminal setting.
if [ -z "$location" ]
then
location="eastus2"
fi
else
location="$DEPLOY_LOCATION"
fi
echo ""
echo "--> Deployment in '$location' location ..."
echo ""
if [ -z "$DEPLOY_PREFIX" ]
then
# Input prefix
echo -n "Enter prefix: "
stty_orig=`stty -g` # save original terminal setting.
read prefix # read the prefix
stty $stty_orig # restore terminal setting.
if [ -z "$prefix" ]
then
prefix="FORTI"
fi
else
prefix="$DEPLOY_PREFIX"
fi
echo ""
echo "--> Using prefix '$prefix' for all resources ..."
echo ""
rg="$prefix-RG"
if [ -z "$DEPLOY_USERNAME" ]
then
# Input username
echo -n "Enter username: "
stty_orig=`stty -g` # save original terminal setting.
read username # read the prefix
stty $stty_orig # restore terminal setting.
if [ -z "$username" ]
then
username="azureuser"
fi
else
username="$DEPLOY_USERNAME"
fi
echo ""
echo "--> Using username '$username' ..."
echo ""
if [ -z "$DEPLOY_PASSWORD" ]
then
# Input password
echo -n "Enter password: "
stty_orig=`stty -g` # save original terminal setting.
stty -echo # turn-off echoing.
read passwd # read the password
stty $stty_orig # restore terminal setting.
echo ""
else
passwd="$DEPLOY_PASSWORD"
echo ""
echo "--> Using password found in env variable DEPLOY_PASSWORD ..."
echo ""
fi
# Create resource group
echo ""
echo "--> Creating $rg resource group ..."
az group create --location "$location" --name "$rg"
# Template validation
echo "--> Validation deployment in $rg resource group ..."
az deployment group validate --resource-group "$rg" \
--template-file azuredeploy.json \
--parameters adminUsername="$username" adminPassword=$passwd fortiGateNamePrefix=$prefix
result=$?
if [ $result != 0 ];
then
echo "--> Validation failed ..."
exit $result;
fi
# Template deployment
echo "--> Deployment of $rg resources ..."
az deployment group create --resource-group "$rg" \
--template-file azuredeploy.json \
--parameters adminUsername="$username" adminPassword=$passwd fortiGateNamePrefix=$prefix
result=$?
if [[ $result != 0 ]];
then
echo "--> Deployment failed ..."
exit $result;
else
echo "
##############################################################################################################
#
# FortiGate Azure deployment using ARM Template
# A single FortiGate
#
# The FortiGate systems is reachable via the public IP address of the firewall on HTTPS/443 and SSH/22.
#
##############################################################################################################
Deployment information:
Username: $username
FortiGate IP addesses
"
query="[?virtualMachine.name.starts_with(@, '$prefix')].{virtualMachine:virtualMachine.name, publicIP:virtualMachine.network.publicIpAddresses[0].ipAddress,privateIP:virtualMachine.network.privateIpAddresses[0]}"
az vm list-ip-addresses --query "$query" --output tsv
echo "
##############################################################################################################
"
fi
exit 0