1
votes

Currently, I am working Azure ARM templates, I developed the ARM templates for a web app and SQL database and deployed those are into azure successful through the VSTS by configuring the CI and CD.

But I want to test the Azure ARM templates and validate them whether these are written correctly or not. For that, I Used the ARM VSTS task but it just validates only.

Before posting a question here, I followed this link but I didn’t understand the answer.

So, can anyone give suggestions on how to test the ARM templates?

2
So, without considering any platform limitations here, what would you ideally want to test?Niels

2 Answers

0
votes

There is no way of testing ARM templates really. The only real way to test ARM templates is to deploy it and validate that proper resources are being created. You can script it, but that's a lot of effort.

Test-AzureRmResourceGroupDeployment is mostly useless as it only validates the syntax which is helpful, but doesnt really guarantee that the template will do what you think it will do.

I cannot really imagine how hard it is to create a proper test for an ARM template, I don't see a lot of value from investing time in creating tests for ARM Templates. I usually use helper scripts that just deploy the template into the dev environment and I quickly validate it. Most of the changes to the ARM templates (even pretty complex ones) do not really require validation.

0
votes

We have too many ways to test an ARM Template. You may consider two tests in your CI/CD Pipeline.

  • Pre deployment Tests :

This can be done using the command :

Test-AzureRmResourceGroupDeployment

To get more control on what you are going to deploy, you can Use Pester + Powershell, write a test scenario and add it as a step in your CI Pipeline.

A new functionnality called "what-if" will be available (according to Build 2019 ARM Template Session)

  • Post Deployment Tests :

For post deployment tests, you may write a JSON defining the expected resources (By their names) then write a script to compare your JSON Definition with the resources that you've deployed.