Environment
Azure
Requisites
Azure cli 2.0
Code:
#!/bin/bash
# Resource group.
azgroup
create --name
myResourceGroup
--locationwestus
# Virtual network.
aznetwork
vnet
create --resource-group
myResourceGroup
--namemyVnet
--subnet-namemySubnet
# Pub IP address.
aznetwork
public-ip
create --resource-group
myResourceGroup
--namemyPublicIP
# Network security group.
aznetwork
nsg
create --resource-group
myResourceGroup
--namemyNetworkSecurityGroup
# Virtual NIC and IP and NSG.
aznetwork
nic
create
\
--resource-group
myResourceGroup \
--name
myNic \
--vnet-name
myVnet \
--subnet
mySubnet \
--network-security-group
myNetworkSecurityGroup \
--public-ip-address
myPublicIP
# New vm with SSH keys
azvm
create --resource-group
myResourceGroup
--namemyVM
--nicsmyNic
--imageUbuntuLTS
--generate-ssh-keys
# Open port 22 to allow SSh traffic to host.
azvm
open-port
--port22 --resource-group
myResourceGroup
--namemyVM