Menu Close

Script: Test ARM Templates and show the resources that will be deployed

Update: I have taken this script and created a module out of this! Check it out here

I was looking for a way to test ARM Templates before the deployment would take place. Of course, the first step is Test-AzureRmResourceGroupDeployment

On it’s own, this is a nice tool. The large issues are displayed before deployment.  I was missing two things though:

  • There is a generic error within this command. An example:

    This isn’t very helpfull information on it’s own.
  • When all is well, this command has no output. So I have to assume I made no mistakes and all resources will deploy as planned

Now let’s fix that.

Don’t need to hear more? Find the script that solves both issues on Github:

The generic error message

This error message is actually usefull 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

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

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

It’s a good thing that you can use powershell to get the logs!
The script will find the tracking ID through regex and outputs the error quick and simple.

Output that shows the resources that will be deployed.

All syntax may be correct, but maybe an error was made within a concat-line. Or you want to do a quick review of a template that was created by someone else.

I was looking for a way to create an output. Then I found this blog

This blog explains how to use the $DebugPreference to get more output. Inspired by the script on that blog, I created an output that shows all resources that will be created. It goes through the first layer of properties. If a nested template is used, it will check those as well. It isn’t perfect (yet), as it misses the more layered properties. But it’s a very good start to me.

The script.

The full script starts with running  Test-AzureRmResourceGroupDeployment
When an error occurs and it’s generic, it will give you the detailed output.
When the test succeeds, it will move on to the next step to get all the resources that will be deployed.

This version of the script is used locally, as it to me is the fasted way to get started with a template. I also have a version that runs in an Azure DevOps Pipeline. Read more about that script here.

So let’s see how it works. I will run the deployment you could see earlier, which creates a storage account

The output is there, plain and easy.

Now I remove the space from the storageaccountname and run the script again

It shows the deployment mode, the resource and the properties.

Now a storageaccount isn’t that exciting. Let’s look at a VM. This is part of the output:

So you see, not perfect yet. But with more complicated resources, I find this very useful.

How to use

Find the script on Github:

You can just download the script TestArmPSLocal.ps1 and run it locally.
Before you do, don’t forget to connect to AzureRM.
The resourcegroup you want to deploy to must exist already.

Test-ArmDeployDetailed -ResourceGroup Resourcegroup1 -TemplatePath .\armdeploy.json -ParametersPath .\armdeploy.parameters.json

Want to use it in a pipeline? Use TestArmPSbuild.ps1. Find a detailed guide in this post.


  1. Pingback:Step by step: Setup a Build & Deploy pipeline in Azure DevOps for ARM templates –

  2. Pingback:Terraform vs ARM Templates: My experience –

  3. Pingback:ARMHelper: A module to help create ARM Templates -

Leave a Reply

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