Part 2 – VM Deployment
In Part 1, we deployed a Virtual Network into Azure in it’s own Resource Group, now we are ready to start deploying some VM’s
With all my VM deployment templates, I try and reference everything to a parameter as much as possible, so you can use the same azuredeploy.json without changing anything, and re-use the parameters.json file over and over again for multiple deployment scenarios
I’ve created this template to deploy; 2 VM’s (with 2 Data Disks), 1 Availability Set, 2 NICs, and 1 Storage Account (NOTE: there is NO Vnet in the template, this is where we reference the Resources to the previously deployed Vnet in Part 1)
"VNetID": "[resourceId(Parameters('networkResourceGroup'), 'Microsoft.Network/virtualNetworks', Parameters('networkname'))]",
You’ll notice that in the template, the VnetID is referencing a parameter “networkResourceGroup” (this is RG-Vnet) and the parameter for “networkname” (this is vnet001)
The same principal applies for the Subnet (Part 1 we deployed the vnet with a Subnet called “snet-ad”)
"ADSubnetRef": "[concat(variables('VNetID'), '/subnets/', Parameters('subnetName'))]",
(Obviously if you are reading this, you already have a pretty good understanding of Azure and ARM Templates)
So let’s deploy the template…
We hit deploy, and fill in all the parameters in the dialog box
There’s that “networkName” parameter, the “subnetName” parameters & “networkResourceGroup” parameter, all of these are the core parameters for deploying your VM’s into an already existing Virtual Network
Deployment took approx 4 minutes….4 MINUTES!!! (I even still amazes me at the speed of the deployments, it would take longer than 4 minutes doing it in the Azure Portal)
Here’s the view in the Portal
And if you drill down into one of the NICs (Network Interface Cards) you’ll see that it’s referencing that Vnet & Subnet in our previously deployed Virtual Network in Par 1)
Hero time
Here is the template…
Deploy.Json
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "stdAdminUserName": { "type": "string", "minLength": 1 }, "stdAdminPassword": { "type": "securestring" }, "storageAccountName": { "type": "string", "minLength": 1 }, "storageAccountType": { "type": "string", "allowedValues": [ "Standard_LRS", "Standard_GRS" ] }, "vmSize": { "type": "string", "minLength": 1 }, "disk1Size": { "type": "int", "defaultValue": 256 }, "disk2Size": { "type": "int", "defaultValue": 256 }, "availabilitySetName": { "type": "string", "minLength": 1 }, "networkName": { "type": "string", "minLength": 1 }, "subnetName": { "type": "string", "minLength": 1 }, "networkResourceGroup": { "type": "string", "minLength": 1 }, "ad01NicName": { "type": "string", "minLength": 1 }, "ad01VMName": { "type": "string", "minLength": 1 }, "ad02NicName": { "type": "string", "minLength": 1 }, "ad02VMName": { "type": "string", "minLength": 1 } }, "variables": { "VNetID": "[resourceId(Parameters('networkResourceGroup'), 'Microsoft.Network/virtualNetworks', Parameters('networkname'))]", "ADSubnetRef": "[concat(variables('VNetID'), '/subnets/', Parameters('subnetName'))]", "stdVMImagePublisher": "MicrosoftWindowsServer", "stdVMImageOffer": "WindowsServer", "stdWindowsOSVersion": "2012-R2-Datacenter", "stdVHDContainerName": "vhds", "AD01OSDiskName": "AD01OSDisk", "AD01DATADisk1Name": "AD01DataDisk1", "AD01DATADisk2Name": "AD01DataDisk2", "AD02OSDiskName": "AD02OSDisk", "AD02DATADisk1Name": "AD02DataDisk1", "AD02DATADisk2Name": "AD02DataDisk2" }, "resources": [ { "name": "[Parameters('storageAccountName')]", "type": "Microsoft.Storage/storageAccounts", "location": "[resourceGroup().location]", "apiVersion": "2015-06-15", "dependsOn": [], "tags": { "displayname": "[Parameters('storageAccountName')]", }, "properties": { "accountType": "[Parameters('storageAccountType')]" } }, { "name": "[Parameters('ad01NicName')]", "type": "Microsoft.Network/networkInterfaces", "location": "[resourceGroup().location]", "apiVersion": "2015-06-15", "tags": { "displayname": "[Parameters('ad01NicName')]" }, "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "subnet": { "id": "[variables('ADSubnetRef')]" } } } ] } }, { "name": "[Parameters('ad02NicName')]", "type": "Microsoft.Network/networkInterfaces", "location": "[resourceGroup().location]", "apiVersion": "2015-06-15", "tags": { "displayname": "[Parameters('ad02NicName')]" }, "properties": { "ipConfigurations": [ { "name": "ipconfig2", "properties": { "privateIPAllocationMethod": "Dynamic", "subnet": { "id": "[variables('ADSubnetRef')]" } } } ] } }, { "name": "[Parameters('availabilitySetName')]", "type": "Microsoft.Compute/availabilitySets", "location": "[resourceGroup().location]", "apiVersion": "2015-06-15", "tags": { "displayname": "[Parameters('availabilitySetName')]" }, "properties": { "platformUpdateDomainCount": 1, "platformFaultDomainCount": 1 } }, { "name": "[Parameters('ad01VMName')]", "type": "Microsoft.Compute/virtualMachines", "location": "[resourceGroup().location]", "apiVersion": "2015-06-15", "dependsOn": [ "[concat('Microsoft.Storage/storageAccounts/', Parameters('storageAccountName'))]", "[concat('Microsoft.Network/networkInterfaces/', Parameters('ad01NicName'))]", "[concat('Microsoft.Compute/availabilitySets/', Parameters('availabilitySetName'))]" ], "tags": { "displayname": "[Parameters('ad01VMName')]" }, "properties": { "availabilitySet": { "id": "[resourceId('Microsoft.Compute/availabilitySets',Parameters('availabilitySetName'))]" }, "hardwareProfile": { "vmSize": "[Parameters('vmSize')]" }, "osProfile": { "computerName": "[Parameters('ad01VMName')]", "adminUsername": "[parameters('stdAdminUserName')]", "adminPassword": "[parameters('stdAdminPassword')]" }, "storageProfile": { "imageReference": { "publisher": "[variables('STDVMImagePublisher')]", "offer": "[variables('STDVMImageOffer')]", "sku": "[variables('stdWindowsOSVersion')]", "version": "latest" }, "osDisk": { "name": "[variables('AD01OSDiskName')]", "vhd": { "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('AD01OSDiskName'), '.vhd')]" }, "caching": "ReadWrite", "createOption": "FromImage" }, "dataDisks": [ { "name": "[variables('AD01DATADisk1Name')]", "createOption": "Empty", "diskSizeGB": "[parameters('disk1Size')]", "caching": "None", "vhd": { "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('AD01DATADisk1Name'), '.vhd')]" }, "lun": 0 }, { "name": "[variables('AD01DATADisk2Name')]", "createOption": "Empty", "diskSizeGB": "[parameters('disk2Size')]", "caching": "None", "vhd": { "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('AD01DATADisk2Name'), '.vhd')]" }, "lun": 1 } ] }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', Parameters('ad01NicName'))]" } ] } } }, { "name": "[Parameters('ad02VMName')]", "type": "Microsoft.Compute/virtualMachines", "location": "[resourceGroup().location]", "apiVersion": "2015-06-15", "dependsOn": [ "[concat('Microsoft.Storage/storageAccounts/', Parameters('storageAccountName'))]", "[concat('Microsoft.Network/networkInterfaces/', Parameters('ad02NicName'))]", "[concat('Microsoft.Compute/availabilitySets/', Parameters('availabilitySetName'))]" ], "tags": { "displayname": "[Parameters('ad02VMName')]" }, "properties": { "availabilitySet": { "id": "[resourceId('Microsoft.Compute/availabilitySets',Parameters('availabilitySetName'))]" }, "hardwareProfile": { "vmSize": "[Parameters('vmSize')]" }, "osProfile": { "computerName": "[Parameters('ad02VMName')]", "adminUsername": "[parameters('stdAdminUserName')]", "adminPassword": "[parameters('stdAdminPassword')]" }, "storageProfile": { "imageReference": { "publisher": "[variables('STDVMImagePublisher')]", "offer": "[variables('STDVMImageOffer')]", "sku": "[variables('stdWindowsOSVersion')]", "version": "latest" }, "osDisk": { "name": "[variables('AD02OSDiskName')]", "vhd": { "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('AD02OSDiskName'), '.vhd')]" }, "caching": "ReadWrite", "createOption": "FromImage" }, "dataDisks": [ { "name": "[variables('AD02DATADisk1Name')]", "createOption": "Empty", "diskSizeGB": "[parameters('disk1Size')]", "caching": "None", "vhd": { "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('AD02DATADisk1Name'), '.vhd')]" }, "lun": 0 }, { "name": "[variables('AD02DATADisk2Name')]", "createOption": "Empty", "diskSizeGB": "[parameters('disk2Size')]", "caching": "None", "vhd": { "uri": "[concat('http://', Parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('AD02DATADisk2Name'), '.vhd')]" }, "lun": 1 } ] }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', Parameters('ad02NicName'))]" } ] } } } ], "outputs": { } }
Parameters.Json
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "stdAdminUserName": { "value": "Craig" }, "storageAccountName": { "value": "sastrgad1001" }, "storageAccountType": { "value": "Standard_LRS" }, "vmSize": { "value": "Standard_D1" }, "disk1Size": { "value": 256 }, "disk2Size": { "value": 256 }, "availabilitySetName": { "value": "avset-ad01" }, "networkName": { "value": "vnet001" }, "subnetName": { "value": "snet-ad" }, "networkResourceGroup": { "value": "RG-Vnet" }, "ad01NicName": { "value": "vm-ad01-nic01" }, "ad01VMName": { "value": "vm-ad01" }, "ad02NicName": { "value": "vm-ad02-nic02" }, "ad02VMName": { "value": "vm-ad02" }, "stdAdminPassword": { "value": "Password1234" } } }Follow @CraigCloudITPro
hi i copied &Pasted your template into visual studio the format is not correct its all jumbled i have latest sdk and 2012 community
LikeLike
Hi Neil, just highlight the whole .json within VS, right click and click “Format Selection”
LikeLike