Skip to content

Instantly share code, notes, and snippets.

@torumakabe
Created March 7, 2018 04:27
Show Gist options
  • Save torumakabe/68e2c4c578fa6557e9663ceca79224f3 to your computer and use it in GitHub Desktop.
Save torumakabe/68e2c4c578fa6557e9663ceca79224f3 to your computer and use it in GitHub Desktop.
#!/bin/bash
BASE_NAME="yourbasename"
echo "[Resource Group ${BASE_NAME}-rg] Creating Resource Group..."
az group create -n ${BASE_NAME}-rg -l japaneast
echo "[VNET vnet01] Creating VNET..."
az network vnet create -g ${BASE_NAME}-rg \
-n vnet01 \
--address-prefix 10.0.0.0/16 \
--subnet-name subnet01 > /dev/null
echo "[NSG subnet01-nsg] Creating NSG..."
az network nsg create -g ${BASE_NAME}-rg -n subnet01-nsg
echo "[NSG subnet01-nsg] Applying NSG..."
az network vnet subnet update -g ${BASE_NAME}-rg \
-n subnet01 \
--vnet-name vnet01 \
--network-security-group subnet01-nsg > /dev/null
echo "[NSG subnet01-nsg] Creating NSG Rule..."
az network nsg rule create -g ${BASE_NAME}-rg \
-n allow-ssh \
--access allow \
--destination-address-prefix '*' \
--destination-port-range 22 \
--direction inbound \
--nsg-name subnet01-nsg \
--protocol tcp \
--source-address-prefix '*' \
--source-port-range '*' \
--priority 1000 > /dev/null
echo "[Jumpbox VM] Creating public IP..."
az network public-ip create -n jumpbox-pip -g ${BASE_NAME}-rg > /dev/null
echo "[Jumpbox VM] Creating NIC..."
az network nic create -g ${BASE_NAME}-rg \
-n jumpbox-nic \
--private-ip-address 10.0.0.254 \
--public-ip-address jumpbox-pip \
--vnet vnet01 \
--subnet subnet01 \
--ip-forwarding > /dev/null
echo "[Jumpbox VM] Creating VM..."
az vm create -g ${BASE_NAME}-rg \
-n jumpbox \
--image Canonical:UbuntuServer:16.04.0-LTS:latest \
--size Standard_B1s \
--nics jumpbox-nic \
--nsg '' > /dev/null
echo "[Jumpbox VM] Copying SSH Key..."
PUBLIC_IP_ADDRESS=$(az network public-ip show -g ${BASE_NAME}-rg \
-n jumpbox-pip --query "ipAddress" -o tsv)
scp ~/.ssh/id_rsa $(whoami)@${PUBLIC_IP_ADDRESS}:~/.ssh/
<< COMMENTOUT
echo "[AvSet as01] Creating AvSet..."
az vm availability-set create -g ${BASE_NAME}-rg -n as01 > /dev/null
echo "[VMs VM-x] Creating VMs..."
for i in 0 1; do
echo "[VM ${i}] Creating public IP..."
az network public-ip create -n vm-${i}-pip -g ${BASE_NAME}-rg > /dev/null
echo "[VM ${i}] Creating NIC..."
az network nic create -g ${BASE_NAME}-rg \
-n vm-${i}-nic \
--private-ip-address 10.0.0.1${i} \
--public-ip-address vm-${i}-pip \
--vnet vnet01 \
--subnet subnet01 \
--ip-forwarding > /dev/null
echo "[VM ${i}] Creating VM..."
az vm create -g ${BASE_NAME}-rg \
-n vm-${i} \
--image Canonical:UbuntuServer:16.04.0-LTS:latest \
--size Standard_B2ms \
--nics vm-${i}-nic \
--availability-set as01 \
--nsg '' > /dev/null
done
COMMENTOUT
echo "[Results] Listing VM..."
az vm list -d -g ${BASE_NAME}-rg -o table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment