When you have many Azure resources to work with, and you are a lazy person who doesn’t want to create the resources one by one, that is when you should use the ARM templates, it is the Microsoft version of Infrastructure as a Code. It has many other advantages too, those are well documented here. Here in this post, we are going to see how you can validate your ARM template. As you might have already known that the ARM template is a JSON file, how difficult is it to validate a JSON file? Things get ugly when you have many resources to work with, there are chances that you miss some important properties, made some syntax issues, most importantly you might have not followed the best practices. So let’s dig in and see how to do this.
ARM Template Test Toolkit
The thing about most of the Cloud Providers is they usually provide all the tools that you may have to work with. The case with Microsoft is no different. We have a tool called ARM Template Toolkit and if you ask me, it is so easy to configure it.
Test Your ARM Template
We will be running some commands in PowerShell, and if you don’t have it in your system, now is the time. Now download the toolkit from this link. Open a PowerShell window and go to the downloaded folder and extract the same, once it is done cd into the folder “arm-ttk”. Now, this is where we are going to run all of our commands.
Get-ChildItem *.ps1, *.psd1, *.ps1xml, *.psm1 -Recurse | Unblock-File
Once it is done, we can import the required module.
There are high chances that you get an error as in the preceding image. This is because of the PowerShell execution policy. No worries, you can easily change the same.
Now we let’s check what our Execution Policy is, and change it. We already have a post about the Execution Policies and reading it wouldn’t be a bad idea. For now, just run the command “Get-ExecutionPolicy” and “Get-ExecutionPolicy -List”.
Now is the time to change the policy, I am going to change it to “ByPass”, so that nothing is blocked. And once that is done, run the Import command again.
Runt the preceding command to validate the ARM template. Finally, yay!!!.
Test-AzTemplate -TemplatePath "C:\Source Code\ArmTemplates\arm-create-resources.json"
As you can see that we get some errors in the red color, and fix them and run it again. Here is how your screen may look like now.
There are many other things that you can do with this tool. For example, integrate it with Azure pipeline and customize the tests, etc. You should be able to do those by reading this post, I wish all the very best.
Here in this post, we have seen how to validate our ARM templates, and this is critical especially when your ARM template is complex. Keep this in your mind whenever you work with ARM templates.
About the Author
I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my blog. And I upload videos on my YouTube channels Njan Oru Malayali and Sibeesh Passion. Please feel free to follow me.
Your turn. What do you think?
Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.