Cloud can be tricky sometimes. Find out what scenarios we've ran into that are worth being mentioned and explained.
Introduction
Azure Resource Manager (ARM) templates are instrumental in automating the deployment of resources within the Azure cloud environment. Leveraging PowerShell commands for deploying ARM templates provides a streamlined and efficient way to manage infrastructure. In this article, we will walk through the process of deploying an ARM template using PowerShell, using an example template that creates a Virtual Machine (VM) and a Virtual Network (VNet). We will then showcase the PowerShell commands needed to deploy this template into a newly created resource group.
JSON:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-06-01",
"name": "MyVnet",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": ["10.0.0.0/16"]
}
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"name": "MyVM",
"location": "[resourceGroup().location]",
"dependsOn": ["MyVnet"],
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"osProfile": {
"computerName": "MyVM",
"adminUsername": "adminUser",
"adminPassword": "yourAdminPassword"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', 'MyVMNic')]"
}
]
}
}
}
]
}
Ensure you replace "yourAdminPassword" with a secure password.
PowerShell:
# Log in to Azure (if not already logged in)
Connect-AzAccount
# Create a resource group (if it doesn't exist)
New-AzResourceGroup -Name „YourResourceGroupName” -Location „YourRegion”
# Deploy the ARM template
New-AzResourceGroupDeployment -ResourceGroupName „YourResourceGroupName” -Mode incremental -TemplateFile azuredeploy.json