Provisioning Azure Resources -- Make It Repeatable!

An intro on how to get started with provisioning your Azure resources using Resource Manager Templates

Scott Lusk
Hitachi Solutions Braintrust
10 min readJun 15, 2019

--

Overview

There are loads of things I love about working with Microsoft Azure as a cloud services provider. My career and job grant me the privilege of working regularly with many of the services that are available within the Azure cloud platform and I love it. I could spend quite a bit of time digging into the different areas and services that I find so appealing when it comes to Azure. However, for this article I want to focus on a brief introduction to what it looks like to provision your Azure resources and how to get started. In Azure, it all starts with creating a resource that will provide services you will then consume in some way.

When it comes to creating resources in Azure, the Azure Portal makes this task quite easy for you. If you’ve spent any time at all in Azure you know all you have to do is click Create a Resource and you are presented with hundreds of options available in the Azure Marketplace to choose from for creating just the right resource(s) you need. Just key in a search word, pick from one of the available categories, or choose a popular item from the list.

Creating a resource in Azure Portal is quick and easy

While this approach certainly can be effective in creating all of your resources, how about when you want to repeat this across multiple environments? Using the Azure Portal does provide a simple and intuitive user interface that makes it quite easy to stand up any resource you could ever need in Azure, but it’s still prone to potential human error. Any touch point that requires a user to input a value, click a button, or perform some action opens itself up for a missed step, typo, inconsistent option selected, and more when applying across separate environments or when multiple persons are involved.

A process such as provisioning all of your resources in Azure should be something that is repeatable regardless of the environment or person trying to set up the necessary resources. It’s important to have a high level of comfort and certainty in knowing that everything is configured exactly the way you expect it to be and that you can produce the same behavior across all environments.

A service Azure provides that will aid you in provisioning your resources is the Azure Resource Manager. Check out the Azure Resource Manager overview in the Microsoft docs for an introduction into all of the details.

Highly Recommended: The overview is an article you should review before going any further into this process. It is also notable that any provisioning work you do — whether in the Azure Portal, Azure PowerShell, Azure CLI, or whatever you are working with — will at some point call into the Azure Resource Manager API that handles your request. It is at the very heart of this entire process and important you know the value it can provide.

Azure Resource Manager is the deployment and management service for Azure. It provides a consistent management layer that enables you to create, update, and delete resources in your Azure subscription.

The Azure Resource Manager is really good at what it does and, more importantly, it knows the best way to do it. Sure, you could take hours, even days, to create each resource independently using Azure Portal but this could be quite tedious or labor intensive to get everything set up just right. How many times have you tried to debug setup issues just to realize it was a simple mistake that was so easily overlooked? Typos are the worst to find when you’ve spent hours trying to track down a deployment issue. I admit, I’ve been there before.

Azure Resource Manager has many benefits for you. It allows you to deploy your resources as a group and repeatedly, with confidence knowing your resources are in a consistent state. Check out the benefits of using Azure Resource Manager to see all the benefits.

With Azure Resource Manager, you can create a template (in JSON format) that defines the infrastructure and configuration of your Azure solution. By using a template, you can repeatedly deploy your solution throughout its life cycle and have confidence your resources are deployed in a consistent state.

As noted in the template deployment section of the Azure Resource Manager overview, templates can be created that allow you to create a repeatable solution to provisioning your resources in Azure. If you aren’t taking advantage of this, you should be. The resource manager templates are where I would like to focus the rest of this article.

In this Article

The goal of this article is to familiarize you with how to get started doing this yourself and, more importantly, becoming aware of a few of the many resources available that can assist you. In upcoming articles, I will go into greater detail about how to build upon this process but I want to make you aware of some resources I find helpful while also noting a few tips along the way. I won’t get too much into the code this time but plan to in future articles.

Pick your editor

You will want to decide what editor to use to author your Resource Manager templates. Visual Studio and Visual Studio Code are good choices for this, or there are other options you can go with such as using the Azure Portal itself. My preference is Visual Studio Code and, if you go that route, be sure to install the Azure Resource Manager Tools extension.

Take a look at any of the Microsoft doc quickstarts to help you get started. Decide which approach you want to take and work through the quickstart.

Pick an example template

As noted in the quickstarts, you can use Azure Quickstart Templates and search for an example to help you get started. For example, search for a standard storage account and start with the same example you see in the quickstart.

You can search for “standard storage account” or go directly to the example at Create a Standard Storage Account. Take a moment to review the details on the page and then click on Browse on GitHub.

In any of the quickstart examples the convention is usually to have files named azuredeploy.json and azuredeployparameters.json. These files don’t necessarily have to be named this but this is the typical convention. The azuredeploy.json is the template file that contains all the resources you plan to provision for a resource group. The parameters file contains any parameters you can pass in to the template to provision the same resources to different environments.

You will typically see multiple parameters files. Parameters files usually have names indicating what environment they will be used for (i.e. azuredeployparameters.dev.json or azuredeployparameters.test.json).

Be sure to check out the Parameters section in the Templates best practices and Parameters section in Template file structure Concepts pages in the Microsoft docs for additional details regarding parameters. The gist is below:

In the parameters section of the template, you specify the values you can input when deploying the resources. These parameter values enable you to customize the deployment by providing values that are tailored for a particular environment (such as dev, test, and production).

Use the API reference

An important resource to be aware of is the API reference. I find myself using it more than any other resource when I author an Azure Resource Manager template. This will help you to understand what is supported for the resources you are trying to create.

If you go to Define resources in Azure Resource Manager templates, down the left hand side you will see a list of resources in the Reference. Any Azure resource you could want to provision should be listed here. As shown on the docs page you can filter by title. In the example below I filter down to see storage account reference. Note, there are multiple API versions you will see available in the list.

Storage Accounts Reference

From the template reference you can choose an API version. You want to select the version that corresponds to the API version you are working with. If you are creating a new resource you may be using the latest version. However, if you are working with an existing template you may need to reference a prior version, so it’s important to know the version and to know the impacts if you want to change it. Any resource you create will have an API version associated with it.

Select an API Version

Other things to note on this docs page:

  • Template format: gives you sample JSON for creating the resource
  • Property values: lists available property values, what is required, expected type, expected or default values, etc.
  • Use any links available on the page to gain additional details about a particular item

Use the Azure Portal

When it comes to authoring templates, as mentioned, I prefer using VS Code. However, I will still drop into the Azure Portal when I want to see how the Microsoft team has authored a particular template.

NOTE: I’ve found the templates generated from the portal always give me more than I need and always take a bit of massaging and tweaks to get to a point I want to run it in the deployment environment. I highly recommend taking the time to review any template you generate from the portal. In my experience it’s rare I stick with the exported template verbatim.

One way to see a template from the portal is to follow the steps at Generate a template using the portal.

Another way to accomplish this is to login to your Azure subscription and select an available resource group from your list. From the resource group there is an option available to Export template. Click this and you will be presented with a template that can be used to provision all of the resources that currently exist in that resource group. I typically scan this template to help gain insight when authoring my own templates.

Export template option available for Resource Groups

Recommendations

Some recommendations based on my experience when working with Resource Manager templates:

  • Keep your templates as small as possible — when adding a resource to the template, only add the properties required or when you need to specify some value other than the default.
  • Use the API reference — this will tell you what properties are available, required, and expected values when working with a resource.
  • Don’t make everything a parameter, only the things you know that will change from environment to environment.
  • Use variables over parameters when possible and when appropriate.
  • Be consistent, use a naming convention for your resources such as a prefix to append to the name.
  • Use a single template per resource group — don’t get in the habit of having multiple templates create the resources in a resource group, let the one template reflect the resource group as a whole.
  • Use Azure Portal Automation to help you export templates — but be sure to review, tweak, and change as needed.
  • Use parameters files — keep one template and multiple parameters files, one per environment you will deploy to.
  • Test often — as with any code, write a small piece of code, then test. Make sure your template is going to do what is expected. I always run this in a sandbox in my own subscription before ever putting it in a client’s subscription.

What is your experience?

I wanted to publish this article as an introduction to this topic for others. As I dig into this in greater depth I will look to give some coding examples. Watch this space, more to come!

What has been your experience? Any tips or recommendations you have that I can add? I would love to hear your comments.

Resources

Example repository available on GitHub at azure-provisioning-demo

Azure Resource Manager

Resource Manager Templates

Azure PowerShell (Az module)

Additional Learning

--

--