You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Network Watcher ARM模板部署失败:资源段长度不匹配问题求助

解决ARM模板部署Network Watcher扩展的验证错误

错误原因

你遇到的InvalidTemplate错误,核心问题是嵌套资源的名称格式不符合ARM模板规则:

  • 类型Microsoft.Compute/virtualMachines/extensions属于VM的子资源,包含3个层级段
  • 对应的资源名称必须包含父资源(VM)和子资源(扩展)的名称,格式为VM名称/扩展名称,即2个段,和类型的段数匹配(根资源类型段数=名称段数+1)

原模板中仅将扩展名称设为networkWatcherAgent,缺少父VM的名称,导致段数不匹配,触发验证失败。

修正后的ARM模板

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string"
        }
    },
    "variables": {
        "apiVersion": "2022-11-01"
    },
    "resources": [
        {
            "name": "[concat(parameters('vmName'), '/networkWatcherAgent')]",
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "apiVersion": "[variables('apiVersion')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
            ],
            "properties": {
                "autoUpgradeMinorVersion": true,
                "publisher": "Microsoft.Azure.NetworkWatcher",
                "type": "NetworkWatcherAgentWindows",
                "typeHandlerVersion": "1.4"
            }
        }
    ]
}

关键修改点

  • 将扩展资源的name字段修改为[concat(parameters('vmName'), '/networkWatcherAgent')],确保名称包含VM名称和扩展名称两个段,与资源类型的层级结构匹配
  • 其余配置保持不变,符合Network Watcher Windows扩展的官方Schema要求

内容的提问来源于stack exchange,提问作者NickP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 19:03:23