ARM TTK 为测试抛出错误:位置不应在 Azure DevOps 管道中硬编码

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

我是 运行 ARM TTK,作为我的 Azure DevOps 管道中的一项任务,用于在合并 PR 之前验证 ARM 模板。 我正在使用的测试之一是:Location Should Not Be Hardcoded 在 link 中提到:ARM-TTK-Tests 的名称为“位置使用参数"

我的 ARM 模板名称不是“azuredeploy.json”或“mainTemplate.json”。我的 ARM 模板名称是“winvm-arm.json”。 我在参数中定义了位置,如下所示:

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

我的资源块中也有对这个参数的引用,如下所示:

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')]"
              }
            }
          }
        ]
      }
    }

所以一切都是正确的,那么为什么测试仍然在下面标记错误:

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

是否因为我的主模板名称不是“azuredeploy.json”或“mainTemplate.json”而被视为嵌套模板,是因为

谢谢Brian Moore。将您的建议作为答案发布以帮助其他社区成员。

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.

可以参考"Location Should Not Be Hardcoded" test catching errors in good templates