#!/bin/bash
# Setup the default subscription if you have never done this before!!
az account set --subscription bd....7 

# create resource group
az group create --name myvm-resource-gp --location ukwest

# List available VM sizes at given location
az vm list-sizes --location ukwest --output table|more  

# Create the VM with default size Standard_DS1_v2
# It's a Unix VM so we will generate SSH keys to allow us to login to it.
az vm create --resource-group myvm-resource-gp --name myVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys

# Show VM details
az vm show --resource-group myvm-resource-gp --name myVM --show-details 

# Create VM with specific size chosen from available sizes
az vm create --resource-group myvm-resource-gp --name myVM2 --size Standard_D2_v2 --image UbuntuLTS --admin-username azureuser --generate-ssh-keys

# Deallocate and restart a VM
az vm deallocate --resource-group myvm-resource-gp --name myVm
az vm start --resource-group myvm-resource-gp --name myVM

# Get the public IP of a VM and SSH into it
az vm show --resource-group myvm-resource-gp --name myVM --show-details --query publicIps

# SSH into VM using the public IP address
ssh azureuser@20.90.8.168
ifconfig  # display the private IP address

# Clean up
az group delete --name myvm-resource-gp --yes
