3
votes

I'm trying to deploy a new VM into a new resource group. The NIC that I'm using for the VM will belong to the new resource group and is to be associated with a subnet from a VNet in another resource group. (this is currently running in Azure, I've exported a template and am working through fixing it up to a working state for future redeployment)

Here's a copy of the error I'm receiving when I try to deploy: 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)

Here's a copy of the JSON template I'm working on.

{
  "$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'))]"
      ]
    }
  ]
}
2
i cannot reproduce this and it looks fine4c74356b41

2 Answers

6
votes

That error usually comes from having a dependency on a resource that is not defined in the template - IOW one of the "dependsOn" arrays contains that resourceId. dependsOn is only for resources defined in the same template.

That said, I don't see that in the json you pasted and as Gleb mentioned, your sample validates just fine for me too.

0
votes

In order to execute the template you will need to ensure that the subnet "devSnDb" is already created. visit https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-create-vnet-arm-ps to find how to create a subnet using powershell or you can create it directly from the interface. You have to target also the right subscription.