Test Your ARM Templates
Tags: azure, devops, infraascode, productivity
Published: 2020-11-16 08:18:38

---
title: Test Your ARM Templates
published: true
description: 
tags: Azure, DevOps, InfraAsCode, Productivity
cover_image: https://geradewebsitestorage.blob.core.windows.net/website/test-arm-templates.png
---

In my [previous post](https://dev.to/raidzen10/azure-resource-manager-arm-template-tips-26c), I talked about best practices for ARM templates. Now I want to share with you a neat little tool that we can use for testing these templates.

###What is the ARM template test toolkit?
The ARM template test toolkit is a tool we can use to test our deployment templates and ensure that we are developing templates that adhere to best practices. If our templates do not follow these recommended best practices this tool will give us warnings with the suggested changes for us to make.

This tool comes a set of default tests you can find here. Remember, these tests are recommendations, meaning you can pick and choose which tests you want to run.

###Installing the Test Toolkit
I am assuming the ttk is still in preview, which is why it hasn’t been added to the PowerShell gallery as of today. Don't stress it though, it takes less that 2 minutes to get it up and running. First, you need to download [this zip file](https://aka.ms/arm-ttk-latest). Once it has been extracted, navigate to the 'arm-ttk' folder in PowerShell.

We need to manually add the test toolkit PowerShell Module to our current session, which we do by running the following command:

`Import-Module .\arm-ttk.psd1`

This command will add the test toolkit module which we can then go ahead and use to test our deployment templates.

> Extract the zip file to the PowerShell modules folder (%ProgramFiles%\WindowsPowerShell\Modules). This way, you don’t have to import the test toolkit module as we are doing above. We can then just call the test command from anywhere because this path is already as part of the ‘PSModulePath’.

###Test Template
To test a template, we use the `Test-AzTemplate` command and provide it with the path to our template. This command will all the default test cases against our template. Below is an example of what the results would look like. The results in green are tests that passed and the ones in red failed.

![Test Results](https://geradewebsitestorage.blob.core.windows.net/website/arm-test-results.PNG)

That’s it. Now we can ensure that our templates follow recommended best practices.

###Continuous Integration
We could even add a step to our build pipeline on Azure DevOps to ensure our templates remain in a good state. All you need to do is add the extension, which you can find here, and add the task to your build.

{% gist https://gist.github.com/GeradeDev/d3c51ae22628ba8bf6658445f608c9f9 %}

###Conclusion
This is a great tool especially for beginners starting to ARM templates. It will guide you in the right direction because I remember when I first started developing ARM I felt so overwhelmed by everything and if whether my templates are correct or not until I did a deployment and went through all the errors.

I hope this helps you and happy deployment - just not Fridays, please. :-)