Azure Stack – IaaS VM ARM Template Deployment & JSON Editors

In this blog post I will write a bit about my opinion why Azure Stack with Azure Resource Manager is the right decision Microsoft has done and which tool to use for editing your JSON template files.

Let us start with the IaaS VM ARM template deployment. If you are a bit familiar with the ARM template design you know that you can deploy a VM with only one template. For demonstration about a specific ARM thing I have created three templates. One for the Storage Account, one for the Virtual Network and the final one for the IaaS VM deployment. Due to the fact that Microsoft has not published a preview version of Azure Stack yet I will use Azure to demonstrate the IaaS VM ARM template deployment.

The first step is to create the appropriate Resource Group for the VM and its resources. I created the Resource Group Azure-Stack in the region West Europe with the following lines of PowerShell.

$ResourceGroupName=”Azure-Stack”
$Location=”westeurope”
New-AzureResourceGroup -Name $ResourceGroupName -Location $Location

Next part is to create the Storage Account under the Resource Group Azure-Stack with an ARM template.

StackARMJSON07

As you can see in the screenshot I am using the following default values for the required parameters.

ParameterValue
newStorageAccountNameazurestackstorage
storageAccountTypeStandard_LRS
locationWest Europe

The following PowerShell cmdlet will start the deployment of the Storage Account.

$ResourceGroupName=”Azure-Stack”
New-AzureResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile “Microsoft.Azure.Stack.Storage.json” -TemplateVersion 1.0.0.0

After the Storage Account is deployed successfully I started the Virtual Network deployment process.

StackARMJSON08

As you can see in the screenshot I am using the following default values for the required parameters.

ParameterValue
locationWest Europe
newVirtualNetworkNameAzure-Stack-Network
addressPrefix172.16.0.0/23
subnetNameManagement
subnetPrefix172.16.0.0/24

The following PowerShell cmdlet will start the deployment of the Virtual Network.

$ResourceGroupName=”Azure-Stack”
New-AzureResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile “Microsoft.Azure.Stack.Network.json” -TemplateVersion 1.0.0.0

As you can see it is very easy to deploy a Resource Group with storage and network resources in Azure or in the upcoming Azure Stack. Thanks to Azure Resource Manager for that, but let us have a look into an IaaS VM ARM template. There will we see why ARM is awesome.

StackARMJSON09

As you can see in the screenshot I am using the following default values for the required parameters.

ParameterValue
newStorageAccountNameazurestackstorage
newVMNameWill be defined during deployment
adminUsernameWill be defined during deployment
adminPasswordWill be defined during deployment
dnsNameForPublicIPazstcp-001
WindowsOSVersion2012-R2-Datacenter

You can even define more parameters or you are using variables for the rest of the definition like I have done it.

StackARMJSON10

For a better identification I concatenated several variables with the VM name and I used for the network configuration the same values I have used in the template file for the Virtual Network.

StackARMJSON11

In the section resources you define the deployment sequence of the different resources. In my example the sequence is the following once.

  1. Storage Account
  2. Public IP Address
  3. Virtual Network
  4. NIC
  5. VM

The special thing about the NIC and the VM is the section dependsOn where you can define dependencies. That means if a dependent resource is not available the deployment of the specific resource will fail. In my case the NIC is dependent from the Public IP Address and the Virtual Network. The VM is dependent from the Storage Account and the NIC.

The following PowerShell cmdlet will start the deployment of the VM.

$ResourceGroupName=”Azure-Stack”
$Credential=Get-Credential
New-AzureResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile “Microsoft.Azure.Stack.Compute.json” -TemplateVersion 1.0.0.0 -Name “AZSTCP-001” -newVMName “AZSTCP-001” -adminUsername $Credential.UserName -adminPassword $Credential.Password

Have a look at the next screenshot. You can see that the deployment was successful. The resources are marked with v2.

StackARMJSON01

But wait how it is possible that the deployment was successful even we had deployed the Storage Account and the Virtual Network before? That is how ARM works. Even if you have deployed resources before and you will use the same name in a template again like it is typical for Storage Accounts and Virtual Networks, ARM checks if the resource exists and will use it. If the resource does not exist ARM will deploy the resource based on the parameters and values defined in the template.

Remember the deployment sequence I have defined in the VM template.

  1. Storage Account
  2. Public IP Address
  3. Virtual Network
  4. NIC
  5. VM

Let us assume that the deployment will fail at step 5 because I have done something wrong in the template definition. The deployment of the VM will fail, but the resources from step 1 to step 4 will be deployed successfully by ARM. That is very important to consider because I can fix the issue in the template file for step 5 and start the deployment again. ARM will check if the resources already exist, then ARM skips step 1 to 4 and continues with step 5. This behavior is a huge step forward for the deployment of IaaS VMs.

When we compare that behavior to the actual deployment behavior of an IaaS VM in a Windows Azure Pack environment it is different. If you discover that the issue for a failed deployment in a Windows Azure Pack environment is a misconfigured template you cannot fix the template and retry the deployment like you can do with ARM. You have to do the following steps.

  1. Delete the failed deployment of the VM
  2. Fix the template
  3. Delete the template
  4. Import the fixed template
  5. Start a new deployment

The reason for that is that a Windows Azure Pack VM template is not modular it is static. The ARM template is modular based because the resources will be deployed independently from other resources if you do not define any dependencies in your template.

Have a look at the following screenshots to get a better understanding for that and get to know why I have concatenated different resources with the VM name.

StackARMJSON01StackARMJSON02StackARMJSON03StackARMJSON04StackARMJSON05StackARMJSON06

The last part in this blog post is about the tools you can use for editing JSON template files. There are a lot of tools you can use and here is a list of some of them.

  • Visual Studio Code
  • Visual Studio
  • Atom
  • PowerShell ISE
  • Notepad++

My favorite tool for editing my JSON template files is the new Visual Studio Code. It is free and available for all of the three major platforms Windows, Linux and Mac.

-> https://code.visualstudio.com/

All of the tools I have mentioned are free. For example Visual Studio comes in different editions, payed and free. For the free one have a look at the Community Edition.

-> http://blogs.msdn.com/b/onecode/archive/2014/11/12/free-visual-studio-community-edition-released-today.aspx

But you have to decide which tool is the best for you and fits your needs.

Here are some links to get started with the Azure Resource Manager and Azure Stack.

-> http://www.itproguy.com/learn-azure-resource-manager/
-> https://github.com/Azure/azure-quickstart-templates
-> http://blogs.technet.com/b/charlesjoy/archive/2015/05/06/azurestack-msignite.aspx
-> http://social.technet.microsoft.com/wiki/contents/articles/30981.azure-stack-wiki-azurestack.aspx

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply