简体   繁体   English

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

[英]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.我正在运行 ARM TTK 作为我的 Azure DevOps 管道中的任务之一,用于在合并 PR 之前验证 ARM 模板。 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 "我正在使用的测试之一是: Location Should Not Be Hardcoded这在链接中提到: ARM-TTK-Tests by the name of " Location Uses Parameter "

My ARM Template name is not "azuredeploy.json" or "mainTemplate.json".我的 ARM 模板名称不是“azuredeploy.json”或“mainTemplate.json”。 My ARM Template name is "winvm-arm.json".我的 ARM 模板名称是“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是不是因为我的主模板名称不是“azuredeploy.json”或“mainTemplate.json”并且它被视为嵌套模板,是这个原因

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可以参考"Location Should Not Be Hardcoded" test catching errors in good templates

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM