azure - 如何解决 ARM 模板中的 'resource is not defined in the template.' 错误?

标签 azure templates arm azure-resource-group

我正在尝试将新虚拟机部署到新资源组中。我用于 VM 的 NIC 将属于新资源组,并将与另一个资源组中 VNet 的子网关联。 (当前正在 Azure 中运行,我已导出模板并正在将其修复为工作状态以供将来重新部署)

这是我尝试部署时收到的错误的副本: Screenshot of error

Deployment template validation failed: 'The resource 'Microsoft.Network/virtualNetworks/prod-vnet/subnets/devSnDb' is not defined in the template. Please see https://aka.ms/arm-template for usage details.'. (Code: InvalidTemplate)

这是我正在处理的 JSON 模板的副本。

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "availabilitySets_dev_bi_as_name": {
      "defaultValue": "dev-bi-as",
      "type": "String"
    },
    "virtualMachines_dev_bi_vm1_name": {
      "defaultValue": "dev-bi-vm1",
      "type": "String"
    },
    "loadBalancers_devSnDb_bi_lb_name": {
      "defaultValue": "devSnDb-bi-lb",
      "type": "String"
    },
    "networkInterfaces_dev_bi_vm1_nic1_name": {
      "defaultValue": "dev-bi-vm1-nic1",
      "type": "String"
    },
    "publicIPAddresses_dev_bi_vm1_pip_name": {
      "defaultValue": "dev-bi-vm1-pip",
      "type": "String"
    },
    "storageAccounts_devbivm1st0_name": {
      "defaultValue": "devbivm1st0",
      "type": "String"
    },
    "extensions_BGInfo_name": {
      "defaultValue": "dev-bi-vm1/BGInfo",
      "type": "String"
    },
    "loadBalancer_InboundNAT_RDP": {
      "defaultValue": "nat-rdp",
      "type": "string"
    },
    "loadBalancers_devSnDb_bi_lb_id": {
      "defaultValue": "/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Network/loadBalancers/devSnDb-bi-lb/frontendIPConfigurations/devSnDblb-frontend",
      "type": "String"
    },
    "existing_vnet_name": {
      "defaultValue": "prod-vnet",
      "type": "string"
    },
    "existing_subnet_name": {
      "defaultValue": "devSnDb",
      "type": "string"
    },
    "virtualNetworkResourceGroup": {
      "defaultValue": "prod-networking-rg",
      "type": "string"
    },
    "networkInterfaces_dev_bi_vm1_nic1_id": {
      "defaultValue": "/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/prod-networking-rg/providers/Microsoft.Network/virtualNetworks/prod-vnet/subnets/devSnDb",
      "type": "String"
    }
  },
  "variables": {
    "LbNatRDPRuleName": "[concat(parameters('virtualMachines_dev_bi_vm1_name'), '-', parameters('loadBalancer_InboundNAT_RDP'))]",
    "LbResourceId": "[resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_devSnDb_bi_lb_name'))]",
    "InboundNatRuleRDPResourceId": "[concat(variables('LbResourceId'), '/inboundNatRules/', variables('LbNatRDPRuleName'))]",
    "vnetResourceId": "[resourceId(parameters('virtualNetworkResourceGroup'),'Microsoft.Network/virtualNetworks', parameters('existing_vnet_name'))]",
    "subnetResourceId": "[concat(variables('vnetResourceID'),'/subnets/', parameters('existing_subnet_name'))]",
    "frontEndIpConfigId": "[concat(variables('LbResourceId'), '/frontendIPConfigurations/devSnDblb-frontend')]"
  },
  "resources": [{
      "comments": "Generalized from resource: '/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Compute/availabilitySets/dev-bi-as'.",
      "type": "Microsoft.Compute/availabilitySets",
      "sku": {
        "name": "Classic"
      },
      "name": "[parameters('availabilitySets_dev_bi_as_name')]",
      "apiVersion": "2016-04-30-preview",
      "location": "australiaeast",
      "scale": null,
      "properties": {
        "platformUpdateDomainCount": 5,
        "platformFaultDomainCount": 3,
        "virtualMachines": [{
          "id": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_dev_bi_vm1_name'))]"
        }]
      },
      "dependsOn": []
    },
    {
      "comments": "Generalized from resource: '/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Compute/virtualMachines/dev-bi-vm1'.",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[parameters('virtualMachines_dev_bi_vm1_name')]",
      "apiVersion": "2016-04-30-preview",
      "location": "australiaeast",
      "scale": null,
      "properties": {
        "availabilitySet": {
          "id": "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySets_dev_bi_as_name'))]"
        },
        "hardwareProfile": {
          "vmSize": "Standard_D11"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "MicrosoftWindowsServer",
            "offer": "WindowsServer",
            "sku": "2016-Datacenter",
            "version": "latest"
          },
          "osDisk": {
            "osType": "Windows",
            "name": "OS",
            "createOption": "FromImage",
            "vhd": {
              "uri": "[concat('https', '://', parameters('storageAccounts_devbivm1st0_name'), '.blob.core.windows.net', concat('/vhds/', parameters('virtualMachines_dev_bi_vm1_name'),'-disk0.vhd'))]"
            },
            "caching": "ReadWrite"
          },
          "dataDisks": [{
            "lun": 0,
            "name": "Data",
            "createOption": "Empty",
            "vhd": {
              "uri": "[concat('https', '://', parameters('storageAccounts_devbivm1st0_name'), '.blob.core.windows.net', concat('/vhds/', parameters('virtualMachines_dev_bi_vm1_name'),'-disk1.vhd'))]"
            },
            "caching": "None",
            "diskSizeGB": 1023
          }]
        },
        "osProfile": {
          "computerName": "[parameters('virtualMachines_dev_bi_vm1_name')]",
          "adminUsername": "foo_admin",
          "windowsConfiguration": {
            "provisionVMAgent": true,
            "enableAutomaticUpdates": true
          },
          "secrets": []
        },
        "networkProfile": {
          "networkInterfaces": [{
            "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_dev_bi_vm1_nic1_name'))]"
          }]
        },
        "diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": true,
            "storageUri": "[concat('https', '://', parameters('storageAccounts_devbivm1st0_name'), '.blob.core.windows.net', '/')]"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySets_dev_bi_as_name'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccounts_devbivm1st0_name'))]",
        "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_dev_bi_vm1_nic1_name'))]"
      ]
    },
    {
      "comments": "Generalized from resource: '/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Network/loadBalancers/devSnDb-bi-lb'.",
      "type": "Microsoft.Network/loadBalancers",
      "name": "[parameters('loadBalancers_devSnDb_bi_lb_name')]",
      "apiVersion": "2017-06-01",
      "location": "australiaeast",
      "scale": null,
      "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "7c725cf2-3995-4a59-8f13-c4d461c641fe",
        "frontendIPConfigurations": [{
          "name": "devSnDblb-frontend",
          "etag": "W/\"a76fdd2a-96d9-4f76-9fa5-87699235647f\"",
          "properties": {
            "provisioningState": "Succeeded",
            "privateIPAllocationMethod": "Dynamic",
            "publicIPAddress": {
              "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_dev_bi_vm1_pip_name'))]"
            }
          }
        }],
        "backendAddressPools": [{
          "name": "devSnDblb-backend",
          "etag": "W/\"a76fdd2a-96d9-4f76-9fa5-87699235647f\"",
          "properties": {
            "provisioningState": "Succeeded"
          }
        }],
        "loadBalancingRules": [],
        "probes": [],
        "inboundNatRules": [{
          "name": "dev-bi-vm1-nat-rdp",
          "etag": "W/\"a76fdd2a-96d9-4f76-9fa5-87699235647f\"",
          "properties": {
            "provisioningState": "Succeeded",
            "frontendIPConfiguration": {
              "id": "[variables('frontEndIpConfigId')]"
            },
            "frontendPort": 3389,
            "backendPort": 3389,
            "enableFloatingIP": false,
            "idleTimeoutInMinutes": 4,
            "protocol": "Tcp"
          }
        }],
        "outboundNatRules": [],
        "inboundNatPools": []
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_dev_bi_vm1_pip_name'))]"
      ]
    },
    {
      "comments": "Generalized from resource: '/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Network/networkInterfaces/dev-bi-vm1-nic1'.",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[parameters('networkInterfaces_dev_bi_vm1_nic1_name')]",
      "apiVersion": "2017-06-01",
      "location": "australiaeast",
      "scale": null,
      "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "e12c648b-fa3c-4f90-92ab-b3901f729f76",
        "ipConfigurations": [{
          "name": "ipconfig1",
          "etag": "W/\"d6de2fab-54c4-4d48-9e40-803eb64995c4\"",
          "properties": {
            "provisioningState": "Succeeded",
            "privateIPAddress": "10.202.14.100",
            "privateIPAllocationMethod": "Static",
            "subnet": {
              "id": "[variables('subnetResourceId')]"
            },
            "primary": true,
            "privateIPAddressVersion": "IPv4",
            "loadBalancerBackendAddressPools": [{
              "id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_devSnDb_bi_lb_name')), '/backendAddressPools/devSnDblb-backend')]"
            }],
            "loadBalancerInboundNatRules": [{
              "id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_devSnDb_bi_lb_name')), '/inboundNatRules/dev-bi-vm1-nat-rdp')]"
            }]
          }
        }],
        "dnsSettings": {
          "dnsServers": [],
          "appliedDnsServers": [],
          "internalDomainNameSuffix": "vekaobcyzqfevo1ktytdiaasbe.px.internal.cloudapp.net"
        },
        "macAddress": "00-0D-3A-D1-57-35",
        "enableAcceleratedNetworking": false,
        "enableIPForwarding": false,
        "primary": true,
        "virtualMachine": {
          "id": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_dev_bi_vm1_name'))]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_devSnDb_bi_lb_name'))]"
      ]
    },
    {
      "comments": "Generalized from resource: '/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Network/publicIPAddresses/dev-bi-vm1-pip'.",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[parameters('publicIPAddresses_dev_bi_vm1_pip_name')]",
      "apiVersion": "2017-06-01",
      "location": "australiaeast",
      "scale": null,
      "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "f3d81651-8042-40b0-8db3-3cff712aa800",
        "ipAddress": "52.237.209.77",
        "publicIPAddressVersion": "IPv4",
        "publicIPAllocationMethod": "Static",
        "idleTimeoutInMinutes": 4
      },
      "dependsOn": []
    },
    {
      "comments": "Generalized from resource: '/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Storage/storageAccounts/devbivm1st0'.",
      "type": "Microsoft.Storage/storageAccounts",
      "sku": {
        "name": "Standard_LRS",
        "tier": "Standard"
      },
      "kind": "Storage",
      "name": "[parameters('storageAccounts_devbivm1st0_name')]",
      "apiVersion": "2016-01-01",
      "location": "australiaeast",
      "tags": {},
      "scale": null,
      "properties": {},
      "dependsOn": []
    },
    {
      "comments": "Generalized from resource: '/subscriptions/13f3d560-8319-4b5b-b762-ca62e0a4a1c7/resourceGroups/dev-bi-rg/providers/Microsoft.Compute/virtualMachines/dev-bi-vm1/extensions/BGInfo'.",
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "[parameters('extensions_BGInfo_name')]",
      "apiVersion": "2016-04-30-preview",
      "location": "australiaeast",
      "scale": null,
      "properties": {
        "publisher": "Microsoft.Compute",
        "type": "BGInfo",
        "typeHandlerVersion": "2.1",
        "autoUpgradeMinorVersion": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_dev_bi_vm1_name'))]"
      ]
    }
  ]
}

最佳答案

该错误通常来自于对模板中未定义的资源的依赖 - IOW“dependsOn”数组之一包含该资源 ID。 dependentOn适用于同一模板中定义的资源。

也就是说,我在您粘贴的 json 中没有看到这一点,正如 Gleb 提到的,您的示例对我来说也验证得很好。

关于azure - 如何解决 ARM 模板中的 'resource is not defined in the template.' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45707314/

相关文章:

AzureMobileClient Database首次手动创建数据表失败?

Azure Functions 最大并发消耗单位

azure - 将 Azure 文件共享映射到 Azure Runbook 本地驱动器以用作临时存储

c++ - 类模板的条件无效成员函数(隐式实例化有效;显式实例化失败)

c++ - 从成员函数模板化参数调用成员函数

基于 Windows 的 ARM 处理器开发

c# - Chrome 驱动程序无法在 Azure Web 应用程序上运行

c++ - 使用类模板需要模板参数列表

linux - 为 Linux 上的裸机 ARM 准备 GNU 工具链

linux - 在 ARM Linux 中记录 CPU 寄存器更改