-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathcreate-high-availability-vm-with-sets.sh
74 lines (66 loc) · 2.13 KB
/
create-high-availability-vm-with-sets.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
#!/bin/bash
# Usage: bash create-high-availability-vm-with-sets.sh <Resource Group Name>
RgName=$1
date
# Create a Virtual Network for the VMs
echo '------------------------------------------'
echo 'Creating a Virtual Network for the VMs'
az network vnet create \
--resource-group $RgName \
--name bePortalVnet \
--subnet-name bePortalSubnet
# Create a Network Security Group
echo '------------------------------------------'
echo 'Creating a Network Security Group'
az network nsg create \
--resource-group $RgName \
--name bePortalNSG
# Add inbound rule on port 80
echo '------------------------------------------'
echo 'Allowing access on port 80'
az network nsg rule create \
--resource-group $RgName \
--nsg-name bePortalNSG \
--name Allow-80-Inbound \
--priority 110 \
--source-address-prefixes '*' \
--source-port-ranges '*' \
--destination-address-prefixes '*' \
--destination-port-ranges 80 \
--access Allow \
--protocol Tcp \
--direction Inbound \
--description "Allow inbound on port 80."
# Create the NIC
for i in `seq 1 2`; do
echo '------------------------------------------'
echo 'Creating webNic'$i
az network nic create \
--resource-group $RgName \
--name webNic$i \
--vnet-name bePortalVnet \
--subnet bePortalSubnet \
--network-security-group bePortalNSG
done
# Create an availability set
echo '------------------------------------------'
echo 'Creating an availability set'
az vm availability-set create -n portalAvailabilitySet -g $RgName
# Create 2 VM's from a template
for i in `seq 1 2`; do
echo '------------------------------------------'
echo 'Creating webVM'$i
az vm create \
--admin-username azureuser \
--resource-group $RgName \
--name webVM$i \
--nics webNic$i \
--image Ubuntu2204 \
--availability-set portalAvailabilitySet \
--generate-ssh-keys \
--custom-data cloud-init.txt
done
# Done
echo '--------------------------------------------------------'
echo ' VM Setup Script Completed'
echo '--------------------------------------------------------'