#Azure ARM Templates
Azure's native Infrastructure as Code.
#Template Structure
json
1{
2 "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3 "contentVersion": "1.0.0.0",
4 "parameters": {
5 "vmName": {
6 "type": "string",
7 "defaultValue": "myVM"
8 }
9 },
10 "variables": {
11 "nicName": "[concat(parameters('vmName'), '-nic')]"
12 },
13 "resources": [
14 {
15 "type": "Microsoft.Compute/virtualMachines",
16 "apiVersion": "2023-03-01",
17 "name": "[parameters('vmName')]",
18 "location": "[resourceGroup().location]",
19 "properties": {
20 "hardwareProfile": {
21 "vmSize": "Standard_B2s"
22 }
23 }
24 }
25 ],
26 "outputs": {
27 "vmId": {
28 "type": "string",
29 "value": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
30 }
31 }
32}#Deploy
bash
1# Create resource group
2az group create --name myRG --location eastus
3
4# Deploy template
5az deployment group create \
6 --resource-group myRG \
7 --template-file template.json \
8 --parameters vmName=myVM#Bicep (Modern Alternative)
bicep
1param vmName string = 'myVM'
2param location string = resourceGroup().location
3
4resource vm 'Microsoft.Compute/virtualMachines@2023-03-01' = {
5 name: vmName
6 location: location
7 properties: {
8 hardwareProfile: {
9 vmSize: 'Standard_B2s'
10 }
11 }
12}[!TIP] Pro Tip: Use Bicep instead of ARM JSON - it's cleaner and compiles to ARM!