0
votes

I'm new for Azure ARM template, what I want to do is quickly build a testing environment from existing resource like web application, SQL server, etc. While I trying deploy from existing resources' ARM template, got some problem , and not sure if there is a good way to test template is going work or not work.

  1. For practice template deploy, I use Azure portal, and created some resources from the Web app + SQL Azure template first.

    (1) Create a resource

    (2) input Web App + SQL

    (3) setting resource names and something, and done.

  2. Then go to source group and export these resources' ARM template.

    (1) Go to Resource group

    (2) click selected all checkbox

    (3) Export template

    (4) Download

  3. Finally, use this template.json to deploy.

    (1) Create a resource

    (2) input template and chose Template deployment (deploy using custom template)

    (3) Build your own template in the editor

    (4) Load file

    (5) upload template.json that downloaded before

    (6) Save

    (7) Select resource group and set resource name without duplicate to resource created before.

    (8) Check "I agree" checkbox and click Purchase button.

So basically I didn't change any resource, just export and deploy, and the deploy failed.

Here is error message:

{
  "code": "DeploymentFailed",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.",
  "details": [
    {
      "code": "Conflict",
      "message": "{\r\n \"status\": \"Failed\",\r\n \"error\": {\r\n \"code\": \"ResourceDeploymentFailure\",\r\n \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n \"details\": [\r\n {\r\n \"code\": \"InvalidParameterValue\",\r\n \"message\": \"Invalid value given for parameter Password. Specify a valid parameter value.\"\r\n }\r\n ]\r\n }\r\n}"
    }
  ]
}

After some research, I find out that if I deploy a SQL Server, I need to set admin password parameter into template too.

What I want to ask is, is there a good way to build ARM template, that you don't need actually go to deploy and get error message to tell you which parameter is missing or something?

Or you just build json file, deploy, and do try & error... :S

2

2 Answers

0
votes

Exported templates are a bit dodgy, to be honest. they export some things, but don't export others, some fields they do export some not. they also tend to create a ton of parameters whereas usually you can get away with prefix parameters + resource suffixes for names and some of the others things can be also hardcoded. To simplify your life a bit you can use VSCode Azure Resource Manager extension, it offers some intellisense and some syntax checks, but some of the intellisense is wrong (lol) and if the template doesnt show any syntax errors it doesn't really mean it will work...

So the only real way to do this is try to deploy\fix errors\repeat.

0
votes

Maybe late to you but can help others. When navigating into Azure docs to automate an ARM deployment I found this 'Whatif' feature which seems to be fresh. I could not test it yet but definitely it's something I want to run before to try deploy anything. I'm assuming that will be making some dependencies checks. I will update here once I test it.

Those are the API reference docs:

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-deploy-what-if

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.resourcemanager.models.deploymentwhatif