Menu Close

ARMHelper: A module to help create ARM Templates

While working with ARM templates, I have created some tools with PowerShell to make it a little bit easier to do debugging and show risks like overwriting resources. I have written a post before about a script that shows the resources that would be deployed. But I felt this script was a bit unpractical as it performed two tasks at once. Plus, I wasn’t always using it because I had to find it in a different folder. As I had some other ideas, I decided to create a module out of them: ARMhelper. The cmdlets are written around Test-AzureRmResourceGroupDeployment.

In this blogpost, I will show some of the current possibilities

Install the module

I have uploaded the module tot the PowerShell Gallery. So to install it, you can simply run the following command:

Install-Module ARMHelper
Import-Module ARMHelper

Get-ARMDeploymentErrorMessage

I will show with an example why I created this function.

Let’s test the deployment of a basic storage account


Test-AzureRmResourceGroupDeployment -ResourceGroupName Test -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json

ArmTest Error

This is a general error that’s not very helpful on its own.

This error message is actually useful when you use it within Azure logging, as you can find that “inner error”. So I can go to the portal, select the activity log and find the error

ARMerror in the portal

This provides a json and if you dig a long way, you can find the error.

ARMerror in the JSON

There we go, there was a space in the name of the storage account.

To make this process a little easier, you can use Get-ARMDeploymentErrorMessage. This cmdlets goes through the errorlog for you and gives you the output that actually tells you what’s wrong.

Get-ARMDeploymentErrorMessage -ResourceGroupName Test -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json

show-armdeployment example storage account

Test-ARMDeploymentResource

This one is my favorite. This function uses the debug output of Test-AzureRMResourcegroupDeployment (or Test-AzResourcegroupDeployment) and creates a list of all the resources that would be deployed. The function needs a resourcegroup that exists, but it will not deploy anything. I have put some time in optimizing the output so it creates a list of properties per resource.

First, I will show the storage account again (with a correct name this time)

Test-ARMDeploymentResource -ResourceGroupName Test -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json

ARMHELPER storage account

It shows you basic properties for the storage account. Want to know more details? The output is an object (or actually an array of objects), so it contains all the properties that are defined in the Resource. If you add Select-Object *, it outputs everything.

Test-ARMDeploymentResource -ResourceGroupName Test -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json | Select-Object *

ARMHELPER storage account

Now let’s look at a Virtual Machine, where a bit more resources are going on

So you get a clear list of what would be deployed if you push this to Azure.

If you pipe the cmdlet to show all properties, you will get all details, like this snippet here

Tools like this can be great to save yourself from typo’s or an error in a concat-line for example

Test-ARMExistingResource

So what this command does, is check in your Azure tenant if the resources you would deploy already exist. It will tell you what the results would be of you running the deployment, depending on if you use incremental mode or complete mode.

As an example, the VM:

Test-ARMExistingResource -ResourceGroupName Test -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json

Now if a resource exists and mode is set to complete, it displays an appropriate amount of caps lock.

Use the module in a pipeline

Of course, this module can be used in a  pipeline in Azure DevOps. Click here to see how. 

I hope the module will be helpful. It is still in beta and there are a lot of different Azure Resources, so you might find a bug I have missed. If you find issues, please let me know on Github.

3 Comments

  1. Pingback:Setup a build pipeline in Azure DevOps for ARM Templates Part II: using ARMHelper and YAML - 4bes.nl

  2. Pingback:Script: Test ARM Templates and show the resources that will be deployed - 4bes.nl

  3. Pingback:Make generated ARM Templates production-ready - 4bes.nl

Leave a Reply

Your email address will not be published. Required fields are marked *