Comparing ARM Templates with Azure Building Blocks – Part 3: ARM In Action

In the previous post, we walked through all the components we need to install and setup in order to work with Azure Building Blocks (ABB).

In this post, we will re-create the same components that were deployed through our Azure Building Blocks (ABB) parameter settings file, but in a standard ARM template.

 

Installation and Setup

In order to use ARM templates, all we need is a code editor. Now, you could use something as simple as Notepad, but there are better options.

My favorite editor is Visual Studio Code. If you’re going to use this editor, you’re also going to want to install the Azure Resource Manager Tools extension. You may also want a few other extensions, depending on what you’re developing, like Azure Tools for Visual Studio Code, Azure Automation, PowerShell, etc.

You will also want to install Azure PowerShell, inclusive of the AzureRM module.

After you have those components setup, the first thing you need to create is an empty ARM template, saved as a .JSON file.

ARM Template - Blank

ARM Template – Blank Template

 

The Template Framework

To mirror the first tutorial for Azure Building Blocks (ABB), we are going to create a template to deploy a single Virtual Network (VNet), with a single Subnet.

In the ARM template, we have a similar “parameters” section. In there, we need to define the Virtual Network name, Address Space, Subnet Name, and it’s address space.

That would look something like this. You will notice some of the differences, such as metadata, descriptions, and default value.

ARM Template - Parameters

ARM Template – Parameters

Why I like the ARM template over the Azure Building Blocks (at least currently), is that we can build the template parameters with AllowedValues. This means we can restrict what people are allowed to input (i.e. restricting locations for deployments, or limiting what size/class of Virtual Machine can be deployed).

At this point, the Azure Building Blocks (ABB) example is complete, since we just reference that file when initiating the deployment. But in the ARM template, we need to define the actual resources.

That would look something like this. Notice how the resources are referencing the parameters we’ve specified earlier. This is essentially what’s occurring behind the scenes in Azure Building Blocks (ABB).

ARM Template - Resources

ARM Template – Resources

 

ARM Deployment

Now that we have our ARM template built, let’s deploy it.

To deploy our ARM template through PowerShell (similar to the Azure CLI used for Azure Building Blocks (ABB)), we use the following commands.

Different than the Azure Building Blocks (ABB) deployment, we need to first create the Resource Group our deployment will go into.

Note: The Azure Building Blocks (ABB) command-line tool determines if the resource group name you pass with the -g option exists or not. If the resource group exists, the command-line tool deploys the resources to the existing resource group. If it doesn’t exist, the command-line tool creates the resource group for you and then deploys the resources to the new resource group.

So that’s one difference between the two tools. To create a new Resource Group in PowerShell, use the following command: New-AzureRmResourceGroup -Name ARMResourceGroup -Location “Canada Central”

ARM Template - PowerShell - New Resource Group

ARM Template – PowerShell – New Resource Group

After you have the Resource Group created, then we can deploy our template using the following command:  New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile C:\MyTemplates\storage.json

ARM Template - PowerShell - New VNet

ARM Template – PowerShell – New VNet

We don’t get an output file like we do with Azure Building Blocks (ABB), but we do get output from PowerShell. So, you could capture that output into a variable, and write it to a log file if you wanted.

And the results are as expected, we have our Azure Virtual Network deployed.

ARM Template - Deployment Results

ARM Template – Deployment Results

One other thing I wanted to mention about ARM template deployment, is that you don’t necessarily have to use PowerShell. In Azure, there is a Templates area, where you can save, iterate, and deploy your templates. You can even share the templates with other team members.

Azure Templates Example

Azure Templates Example

And when you deploy your template through this mechanism, you obtain the option to create a new Resource Group as part of this deployment (which we don’t get as a one-liner using the PowerShell method demonstrated earlier).

Azure Templates Deployment Example

Azure Templates Deployment Example

 

Conclusion

Just to reiterate and summarize, with Azure Building Blocks (ABB), we don’t need to spend the time and effort in declaring and defining the resources themselves, but that also means we don’t have as much control over the outcome. It also means we have to install the handful of tools, packages, etc. in order to work with Azure Building Blocks (ABB), especially within a development team. Whereas PowerShell in already installed on most systems, and it’s a simple one-liner to import that AzureRM module.

It would be nice to see if the Azure Templates area will be expanded to include the options for both ARM and Azure Building Blocks (ABB).

Like I mentioned, if you want to restrict the allowed values to a subset, then you still need to use ARM templates. Also, since Azure Building Blocks (ABB) is new, the number of templates to start will, of course, be a little limited (though expanded upon in time).

So although the Azure Building Blocks (ABB) adheres to Microsoft proven and best-practices, we all know that sometimes these recommended practices are not applicable to our organization or environment.

Just a few things to keep in mind if you’re going to use these new building blocks.

Leave a Reply

%d bloggers like this: