【问题标题】:Azure arm template validationAzure 手臂模板验证
【发布时间】:2023-03-04 23:59:02
【问题描述】:

我的 ARM 模板代码失败并出现以下验证错误。

域加入应该等到自定义脚本扩展完成。请参阅下面的代码。我无法理解资源和子资源依赖项如何工作以及如何命名资源。不胜感激,如果你能指导我一篇文章来学习。

   {
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/cse')]",
    "apiVersion": "2017-03-30",
    "location": "[variables('varlocation')]",
    "dependsOn": [
      "[concat(variables('varnodeNamePrefix'),copyindex(1))]"
    ],
    "properties": {
      "publisher": "Microsoft.Compute",
      "type": "CustomScriptExtension",
      "typeHandlerVersion": "1.8",
      "autoUpgradeMinorVersion": true,
      "settings": {
        "fileUris": [
          "https://XXXXXXXXXXX.blob.core.windows.net/powershelscripts/sqlcluster/InstallAdditionalModules.ps1"
        ]
      },
      "protectedSettings": {
        "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted ./sqlcluster/InstallAdditionalModules.ps1",
        "storageAccountName": "sdfsdfsdfsdf",
        "storageAccountKey": "sdsdfsdf/BH9C+fdgdfgdfgdfg+fgdfgdfg=="
      }
    },
    "copy": {
      "name": "WinFeatures",
      "count":"[variables('varvmCount')]"
    }
 },

 {
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/joindomain')]",
  "location": "[resourceGroup().location]",
  "dependsOn": ["[concat(variables('varnodeNamePrefix'),copyindex(1),'/cse')]"            
               ],
  "properties": {
    "publisher": "Microsoft.Compute",
    "type": "JsonADDomainExtension",
    "typeHandlerVersion": "1.3",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "Name": "[variables('vardomainToJoin')]",
      "User": "[concat(variables('vardomainToJoin'), '\\', variables('vardomainUsername'))]",
      "Restart": "true",
      "Options": "[variables('vardomainJoinOptions')]"
    },
    "protectedSettings": {
      "Password": "[variables('vardomainPassword')]"
    }
  },
  "copy": {
    "name": "joindomain",
    "count":"[variables('varvmCount')]"
  }

【问题讨论】:

    标签: azure azure-resource-manager arm-template azure-template


    【解决方案1】:

    resourceId 错误,应该是这样的:

    "[resourceId('Microsoft.Compute/virtualMachines/extensions',concat(variables('varnodeNamePrefix'),copyindex(1)),'extensions')]"
    

    或者简单地说:

    concat(variables('varnodeNamePrefix'),copyindex(1),'/extensions')
    

    错误告诉你什么 - 你在这里有 3 个片段:Microsoft.Compute/virtualMachines/extensions,但之后只有 1 个片段:concat(variables('varnodeNamePrefix'),copyindex(1),'/extensions'))

    但它应该有 2 个片段,因为它试图这样做:

    Microsoft.Compute/virtualMachines/{segment1}/extensions/{segment2}
    

    工作再现:

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {},
        "variables": {
            "varnodeNamePrefix": "testing"
        },
        "resources": [
            {
                "type": "Microsoft.Compute/virtualMachines/extensions",
                "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/cse')]",
                "apiVersion": "2017-03-30",
                "location": "[resourceGroup().location]",
                "properties": {
                    "publisher": "Microsoft.Compute",
                    "type": "CustomScriptExtension",
                    "typeHandlerVersion": "1.8",
                    "autoUpgradeMinorVersion": true,
                    "settings": {
                        "fileUris": [
                            "https://XXXXXXXXXXX.blob.core.windows.net/powershelscripts/sqlcluster/InstallAdditionalModules.ps1"
                        ]
                    },
                    "protectedSettings": {
                        "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted ./sqlcluster/InstallAdditionalModules.ps1",
                        "storageAccountName": "sdfsdfsdfsdf",
                        "storageAccountKey": "sdsdfsdf/BH9C+fdgdfgdfgdfg+fgdfgdfg=="
                    }
                },
                "copy": {
                    "name": "WinFeatures",
                    "count": 3
                }
            },
            {
                "apiVersion": "2015-06-15",
                "type": "Microsoft.Compute/virtualMachines/extensions",
                "name": "[concat(variables('varnodeNamePrefix'),copyindex(1),'/joindomain')]",
                "location": "[resourceGroup().location]",
                "dependsOn": [
                    "[resourceId('Microsoft.Compute/virtualMachines/extensions',concat(variables('varnodeNamePrefix'),copyindex(1)),'cse')]"
                ],
                "properties": {
                    "publisher": "Microsoft.Compute",
                    "type": "JsonADDomainExtension",
                    "typeHandlerVersion": "1.3",
                    "autoUpgradeMinorVersion": true,
                    "settings": {
                        "Name": "yyy.zzz",
                        "User": "[concat('xxx', '\\', 'xxx')]",
                        "Restart": "true"
                    },
                    "protectedSettings": {
                        "Password": "xxx"
                    }
                },
                "copy": {
                    "name": "joindomain",
                    "count": 3
                }
            }
        ]
    }
    

    完整的工作示例:https://paste.ee/p/XlBHY(基本上与上面写的相同)

    【讨论】:

    • 谢谢..我对此感到困惑..我将自定义扩展名命名为 concat(variables('varnodeNamePrefix'),copyindex(1),'/joindomain')。我的理解(如您所知是错误的)是主要资源名称是我们应该在依赖资源中使用的名称..以及什么是段以及我在哪里可以了解更多信息。
    • 嗯,一个段 = / 之间的任何东西,你的资源名称很好,应该是这样。错误在取决于参数中,就像我指定的一样
    • 对不起。我还是不关注你。 new-azResourceGroupDeployment:10:27:37 - 错误:代码=无效模板;消息=部署模板验证失败:'资源'Microsoft.Compute/virtualMachines/XX-XXX-UKW-XXX/extensions/extensions'未在模板中定义。请参阅aka.ms/arm-template 了解使用详情。'.
    • new-azResourceGroupDeployment:10:51:49 - 错误:代码=无效模板;消息=部署模板验证失败:“439 行和“9”列的模板资源“DI-DEV-XXX-DB1/joindomain”无效:资源标识符“DI-XXX-UKW-DB1/extensions”格式不正确。使用详情请参阅aka.ms/arm-template-expressions/#reference。有关使用详情,请参阅aka.ms/arm-template-expressions。'.
    • "dependsOn": ["[concat(variables('varnodeNamePrefix'),copyindex(1),'/extensions')]" ],
    猜你喜欢
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多