Azure Resource Manager is the deployment and management service for Azure. It provides a consistent management layer that enables you to create, update, and delete resources in your Azure subscription. You can use its access control, auditing, and tagging features to secure and organize your resources after deployment.

There are no prebuilt ARM templates or PowerShell scripts available from NGINX currently. However, there is nothing preventing the creation of an ARM template and PowerShell script based on your custom deployment requirements for Azure using your custom VM images previously created.

The following provides an example of creating an Ubuntu 16.04 LTS marketplace image from Canonical along with the NGINX web server using the Azure Cloud Shell and the Azure PowerShell module.

Open the Azure Cloud Shell and the perform the following steps in Azure PowerShell:

1. Use ssh-keygen to create an SSH key pair:
ssh-keygen -t rsa -b 2048

2. Create an Azure resource group with New-AzResourceGroup:
New-AzResourceGroup -Name “myResourceGroup” -Location “EastUS”

3. Create a virtual network, subnet, and a public IP address:

# Create a subnet configuration
$subnetConfig = New-AzVirtualNetworkSubnetConfig
 -Name "mySubnet"

 -AddressPrefix 192.168.1.0/24

# Create a virtual network
$vnet = New-AzVirtualNetwork
 -ResourceGroupName "myResourceGroup"

 -Location “EastUS”
 -Name "myVNET"

 -AddressPrefix 192.168.0.0/16
 -Subnet $subnetConfig

# Create a public IP address and specify a DNS name
$pip = New-AzPublicIpAddress

 -ResourceGroupName “myResourceGroup”
 -Location "EastUS"

 -AllocationMethod Static
 -IdleTimeoutInMinutes 4

 -Name “mypublicdns$(Get-Random)”

4. Create an Azure Network Security Group and traffic rule:

# Create an inbound network security group rule for port 22
$nsgRuleSSH = New-AzNetworkSecurityRuleConfig
-Name "myNetworkSecurityGroupRuleSSH"

-Protocol “Tcp”
-Direction "Inbound"

-Priority 1000
-SourceAddressPrefix *

-SourcePortRange *
-DestinationAddressPrefix *

-DestinationPortRange 22
-Access "Allow"

# Create an inbound network security group rule for port 80
$nsgRuleWeb = New-AzNetworkSecurityRuleConfig

-Name “myNetworkSecurityGroupRuleWWW”
-Protocol "Tcp"

-Direction “Inbound”
-Priority 1001

-SourceAddressPrefix *
-SourcePortRange *

-DestinationAddressPrefix *
-DestinationPortRange 80

-Access “Allow”

# Create a network security group
$nsg = New-AzNetworkSecurityGroup
-ResourceGroupName "myResourceGroup"

-Location “EastUS”
-Name "myNetworkSecurityGroup"

-SecurityRules $nsgRuleSSH,$nsgRuleWeb

5. Create a virtual network interface card (NIC) with New-AzNetworkInterface:

# Create a virtual network card and associate with public IP address and NSG
$nic = New-AzNetworkInterface
-Name "myNic"

-ResourceGroupName “myResourceGroup”
-Location "EastUS"

-SubnetId $vnet.Subnets[0].Id
-PublicIpAddressId $pip.Id

-NetworkSecurityGroupId $nsg.Id

6. Create a virtual machine. In this example, the SSH key is stored in ~/.ssh/id_rsa.pub

# Define a credential object
$securePassword = ConvertTo-SecureString ‘ ‘ -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential (“azureuser”, $securePassword)

# Create a virtual machine configuration
$vmConfig = New-AzVMConfig
-VMName "myVM"

-VMSize “Standard_D1” |
Set-AzVMOperatingSystem

-Linux
-ComputerName "myVM"

-Credential $cred
-DisablePasswordAuthentication |

Set-AzVMSourceImage
-PublisherName "Canonical"

-Offer “UbuntuServer”
-Skus "16.04-LTS"

-Version “latest” |
Add-AzVMNetworkInterface

-Id $nic.Id

# Configure the SSH key
$sshPublicKey = cat ~/.ssh/id_rsa.pub Add-AzVMSshPublicKey
-VM $vmconfig

-KeyData $sshPublicKey
-Path "/home/azureuser/.ssh/authorized_keys"

7. Now, combine the previous configuration definitions to create with New-AzVM:

New-AzVM
-ResourceGroupName “myResourceGroup” `
-Location eastus -VM $vmConfig

8. Connect to the VM once it is created. Create an SSH connection with the VM using the public IP address. To see the public IP address of the VM, use the Get-AzPublicIpAddress cmdlet:

Get-AzPublicIpAddress -ResourceGroupName “myResourceGroup” | Select “IpAddress”

9. Paste the SSH connection command into the shell to create an SSH session:

ssh azureuser@10.111.12.123

10. Install the NGINX web server. From your SSH session, update your package sources and then install the latest NGINX package:

sudo apt-get -y update
sudo apt-get -y install nginx

11. When done, type exit to leave the SSH session. Use a web browser of your choice to view the default NGINX welcome page. Enter the public IP address of the VM as the web address.