Azure Resource Manager(ARM) was announced in Spring 2014. It is a completely different way of deploying services on Azure platform. It matters because before the release of ARM it was only possible to deploy one service at a time. When you were deploying applications using PowerShell or Azure CLI you had to deploy all the services via a script. As the number of services increased the scripts got increasingly complex and brittle. Over the past year ARM capabilities have evolved rapidly. All future services will be deployed via ARM cmdlets or templates. The current Azure Service management API’s will be eventually deprecated. Even when using ARM you have two choices:
- Imperative: This is very similar to how you were using Service Management API’s to provision services.
- Declarative: Here you define the application configuration with a JSON Template. This template can be parameterized. Once this is done a single PowerShell cmdlet New-AzureResourceGroupDeployment deploys your entire application. This deployment can span regions as well. You can define dependencies between resources and deployment process will deploy them in the order necessary to make the deployment successful. If there are no dependencies it parallelizes the deployment. You can repeatedly deploy the same template and the deployment process is smart enough to determine what changed and only deploy/update the services that changed. ARM templates can not only provision the infrastructure they also also execute tasks inside the provisioned VM’s to fully configure your application. On Windows VM’s you can either use DSC or PowerShell scripts to customize it. On Linux you can use bash scripts to customize the VM after it has been created.
AWS has had a similar capability for many years. It is called CloudFormation. While ARM and CloudFormation are similar and are trying to achieve similar goals there are some differences between them as well.
If you believe in DevOps and work with Microsoft Azure platform understanding ARM will be beneficial. Another thing worth mentioning is that ARM templates will allow you to deploy services in your private cloud when Azure stack is released. I want to share some helpful resources to make it easier for you to learn ARM.
- Treat your Azure Infrastructure as code is an excellent overview of ARM and its benefits: https://www.linkedin.com/pulse/treat-your-azure-infrastructure-code-krishna-venkataraman?trk=prof-post
- ARM Language Reference: https://msdn.microsoft.com/en-us/library/azure/Dn835138.aspx?f=255&MSPPError=-2147217396
- Azure Quick Start Templates at Github: If you are like me you learn from examples. Here is a large repository of ARM templates. https://github.com/Azure/azure-quickstart-templates
- Ryan Jones from Microsoft posted many simple ARM samples here: https://github.com/rjmax/ArmExamples
- Full Scale 180 blog is another excellent resource to learn how to write ARM templates. http://blog.fullscale180.com/building-azure-resource-manager-templates/ I especially like the Couchbase Sample: https://github.com/Azure/azure-quickstart-templates/tree/master/couchbase-on-ubuntu
- If you still want to use the imperative method of deploying Azure resource check out this sample for Joe Davies that walks you through the process provisioning a VM here: https://azure.microsoft.com/blog/2015/06/11/step-through-creating-resource-manager-virtual-machine-powershell/
- Here is a sample showing how to lock down your resources with Resource Manager Lock. http://blogs.msdn.com/b/cloud_solution_architect/archive/2015/06/18/lock-down-your-azure-resources.aspx
- Neil Mackenzie posted a sample for creating a VM with a instance IP address here: https://gist.github.com/nmackenzie/db9a4b7abdee2760dba8 https://onedrive.live.com/view.aspx?resid=96BA3346350A5309!318670&app=OneNote&authkey=!APNWE3DZp1C-RjY
- Alexandre Brisebois posted a sample showing how to provision Centos VM using an ARM. In this example he shows how to customize the VM after its creation using a bash script. https://alexandrebrisebois.wordpress.com/2015/05/25/create-a-centos-virtual-machine-using-azure-resource-manager-arm/
- Kloud Blog has a nice overview of how to get started with ARM and many samples: http://blog.kloud.com.au/tag/azure-resource-manager/
- If you want learn about best practices for writing ARM templates this is a must read document. https://azure.microsoft.com/en-us/documentation/articles/best-practices-resource-manager-design-templates/
- This blog post shows how you can use output section of the template publish information about newly created resources. http://blogs.msdn.com/b/girishp/archive/2015/06/16/azure-arm-templates-tips-on-using-outputs.aspx
- Check out this list of resources for ARM by Hans Vredevoort. It is very comprehensive. https://onedrive.live.com/view.aspx?resid=96BA3346350A5309!318670&app=OneNote&authkey=!APNWE3DZp1C-RjY
- This blog post shows how you can use arrays, length function, resource loops, outputs to provision multiple storage accounts http://184.108.40.206/2015/08/14/adventures-with-azure-resource-manager-part-i/
As I work with ARM templates I am constantly developing or looking for samples that can help me. These sample templates were created by product teams in Microsoft but have not been integrated into Quick Start templates yet. I will use this section to document some of the helpful samples I have found.
- Azure Web Site with a Web Job Template: This template was created by David Ebbo. This is the only ARM template sample that shows you how to publish webjobs with an ARM template. https://github.com/davidebbo/AzureWebsitesSamples/blob/master/ARMTemplates/WebAppWithWebJobs.json
- Length Function: As I began learning the template language I found it annoying that I had to pass in Array and its length as separate parameters. I just found a sample created by Ryan Jones which shows how to calculate length of an array. https://github.com/rjmax/ArmExamples/blob/master/copySampleWithLength.json
ARM documentation is still evolving and sometimes it is difficult to find samples you are looking for. If you are trying to create a new template and you cannot find any documentation here are few things that may be helpful
- Azure Resource Explorer: This is an essential tool for anybody writing ARM templates. You can deploy a resource using the portal and use the resource explorer to see the JSON schema for the resource you just created. You can make changes to the resources: https://resources.azure.com/
- ARM Schemas: This is the location where MSFT ARM teams are posting their schemas. https://github.com/Azure/azure-resource-manager-schemas
You can view the logs using these PowerShell cmdlets.
- Get-AzureResourceLog: Gets logs for a specific Azure resource
- Get-AzureResourceGroupLog: Get logs for a Azure resource group
- Get-AzureResourceProviderLog Gets logs for an Azure resource provider
- Get-AzureResourceGroupDeploymentOperation Get logs for the deployment operation
When your template deployment operation fails the error message may not have enough detail to tell you the reason for failure. You can go to the preview azure portal and examine the audit logs. You can filter by resource group, resource type, and time range. I was able to get detailed error message from the portal.
In addition to running the cmdlet Switch-AzureMode –Name AzureResourceManager I also had to enable my subscription for specific Azure resource providers. When I was using Service Management API’s this was not necessary. As an example to be able to provision virtual networks with ARM I had to run the following cmdlet:
Register-AzureProvider –ProviderNamespace Microsoft.Network
Even though Template language can work with JSON arrays it cannot determine the number of elements in the JSON array so you have to pass the count separately. on 08/04/2015 I removed the previous line as length function is now available.
I hope these resources are helpful. If you are aware of other helpful ARM resources feel free to mention them in comments on this blog post and I can add them to my list.
I will be posting ARM samples on my blog as well.