Search code examples
azureazure-devopsazure-pipelinesazure-resource-managerazure-powershell

ARM TTK throwing error for the test : Location Should Not Be Hardcoded in Azure DevOps Pipeline


I am running ARM TTK as one of the tasks in my Azure DevOps Pipeline for validating ARM Templates before a PR is merged. One of the tests that i am using is : Location Should Not Be Hardcoded which is mentioned in the link : ARM-TTK-Tests by the name of "Location Uses Parameter"

My ARM Template name is not "azuredeploy.json" or "mainTemplate.json" . My ARM Template name is "winvm-arm.json". I have the location defined in parameters like shown below :

"location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }

I also have the reference to this parameter in my resource block like shown below :

resources": [
    {
      "apiVersion": "2020-05-01",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[concat(variables('vmName'), '-nic')]",
      "location": "[parameters('location')]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "subnet": {
                "id": "[variables('subnetRef')]"
              }
            }
          }
        ]
      }
    }

So everything is correct as per what it should be then why is the test still flagging the error below :

Location Should Not Be Hardcoded (12 ms) 
        The location parameter of nested templates must not have a defaultValue property. It is "[resourceGroup().location]" 

Is it because my main template name is not "azuredeploy.json" or "mainTemplate.json" and it is being treated as a nested template , is that the reason


Solution

  • Thank you Brian Moore. Posting your suggestion as an answer to help other community members.

    this is because anything that is not the "main template" is assumed to be a nested template... main template is determined by the filename (unless you specify otherwise).

    I think short term you'll have to follow the pattern - until we have a more standard way of determining name / nested.

    You can refer to "Location Should Not Be Hardcoded" test catching errors in good templates