-
Notifications
You must be signed in to change notification settings - Fork 254
/
setup-script.sh
executable file
·148 lines (119 loc) · 3.44 KB
/
setup-script.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
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# Variables
resourceGroup="acdnd-c4-project"
location="westus"
osType="Ubuntu2204"
vmssName="udacity-vmss"
adminName="udacityadmin"
storageAccount="udacitydiag$RANDOM"
bePoolName="$vmssName-bepool"
lbName="$vmssName-lb"
lbRule="$lbName-network-rule"
nsgName="$vmssName-nsg"
vnetName="$vmssName-vnet"
subnetName="$vnetName-subnet"
probeName="tcpProbe"
vmSize="Standard_B1s"
storageType="Standard_LRS"
# Create resource group.
# This command will not work for the Cloud Lab users.
# Cloud Lab users can comment this command and
# use the existing Resource group name, such as, resourceGroup="cloud-demo-153430"
echo "STEP 0 - Creating resource group $resourceGroup..."
az group create \
--name $resourceGroup \
--location $location \
--verbose
echo "Resource group created: $resourceGroup"
# Create Storage account
echo "STEP 1 - Creating storage account $storageAccount"
az storage account create \
--name $storageAccount \
--resource-group $resourceGroup \
--location $location \
--sku Standard_LRS
echo "Storage account created: $storageAccount"
# Create Network Security Group
echo "STEP 2 - Creating network security group $nsgName"
az network nsg create \
--resource-group $resourceGroup \
--name $nsgName \
--verbose
echo "Network security group created: $nsgName"
# Create VM Scale Set
echo "STEP 3 - Creating VM scale set $vmssName"
az vmss create \
--resource-group $resourceGroup \
--name $vmssName \
--image $osType \
--vm-sku $vmSize \
--nsg $nsgName \
--subnet $subnetName \
--vnet-name $vnetName \
--backend-pool-name $bePoolName \
--storage-sku $storageType \
--load-balancer $lbName \
--custom-data cloud-init.txt \
--upgrade-policy-mode automatic \
--admin-username $adminName \
--generate-ssh-keys \
--verbose
echo "VM scale set created: $vmssName"
# Associate NSG with VMSS subnet
echo "STEP 4 - Associating NSG: $nsgName with subnet: $subnetName"
az network vnet subnet update \
--resource-group $resourceGroup \
--name $subnetName \
--vnet-name $vnetName \
--network-security-group $nsgName \
--verbose
echo "NSG: $nsgName associated with subnet: $subnetName"
# Create Health Probe
echo "STEP 5 - Creating health probe $probeName"
az network lb probe create \
--resource-group $resourceGroup \
--lb-name $lbName \
--name $probeName \
--protocol tcp \
--port 80 \
--interval 5 \
--threshold 2 \
--verbose
echo "Health probe created: $probeName"
# Create Network Load Balancer Rule
echo "STEP 6 - Creating network load balancer rule $lbRule"
az network lb rule create \
--resource-group $resourceGroup \
--name $lbRule \
--lb-name $lbName \
--probe-name $probeName \
--backend-pool-name $bePoolName \
--backend-port 80 \
--frontend-ip-name loadBalancerFrontEnd \
--frontend-port 80 \
--protocol tcp \
--verbose
echo "Network load balancer rule created: $lbRule"
# Add port 80 to inbound rule NSG
echo "STEP 7 - Adding port 80 to NSG $nsgName"
az network nsg rule create \
--resource-group $resourceGroup \
--nsg-name $nsgName \
--name Port_80 \
--destination-port-ranges 80 \
--direction Inbound \
--priority 100 \
--verbose
echo "Port 80 added to NSG: $nsgName"
# Add port 22 to inbound rule NSG
echo "STEP 8 - Adding port 22 to NSG $nsgName"
az network nsg rule create \
--resource-group $resourceGroup \
--nsg-name $nsgName \
--name Port_22 \
--destination-port-ranges 22 \
--direction Inbound \
--priority 110 \
--verbose
echo "Port 22 added to NSG: $nsgName"
echo "VMSS script completed!"