Share via


Azure Resource Manager - Receiving a "resource...is not defined in a template" related to referencing a VNet in another resource group

Question

Wednesday, July 1, 2015 7:21 PM | 1 vote

When attempting to test out referencing a VNet defined in another resource group from my resource template, I get the "resource 'Microsoft.Network/virtualNetworks/other-resourcegroup-vnet' is not defined in a template error". The goal of the test resource template is to create a Nic (similar to how it is done in the documentation for the resourceid() function). A copy of my test template is below.

The target VNet does exist and was created using a resource template. I verified that the VNet was created utilizing the "Microsoft.Network" provider and that I'm referencing that provider in the test template.

Any insight on what I am doing wrong would be greatly appreciated.

Here is the json for my test template:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "parameters": {
        "other-resourcegroup-vnetLocation": {
            "type": "string",
            "defaultValue": "South Central US",
            "allowedValues": [
                "East US",
                "West US",
                "West Europe",
              "East Asia",
              "South Central US",
                "South East Asia"
            ]
        },
        "MyTestNicName": {
            "type": "string"
        }
    },
    "variables": {
        "other-resourcegroup-vnetSubnet1Name": "Subnet-1",
      "other-resourcegroup-vnetSubnet2Name": "Subnet-2",
      "VNetResourceGroup": "RDBTestVNet",
        "MyTestNicVnetID": "[resourceId(variables('VNetResourceGroup'),'Microsoft.Network/virtualNetworks', 'other-resourcegroup-vnet')]",
        "MyTestNicSubnetRef": "[concat(variables('MyTestNicVnetID'),'/subnets/', variables('other-resourcegroup-vnetSubnet1Name'))]"
    },
    "resources": [
        {
            "name": "[parameters('MyTestNicName')]",
            "type": "Microsoft.Network/networkInterfaces",
            "location": "[parameters('other-resourcegroup-vnetLocation')]",
            "apiVersion": "2015-05-01-preview",
            "dependsOn": [
                "[concat('Microsoft.Network/virtualNetworks/', 'other-resourcegroup-vnet')]"
            ],
            "tags": {
                "displayName": "MyTestNic"
            },
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "privateIPAllocationMethod": "Dynamic",
                            "subnet": {
                                "id": "[variables('MyTestNicSubnetRef')]"
                            }
                        }
                    }
                ]
            }
        }
    ],
    "outputs": {
    }
}

All replies (4)

Thursday, July 2, 2015 7:36 PM ✅Answered | 3 votes

I discovered what the problem was. Removing the dependency on the virtual network from the Network Interface resource definition fixed the problem. To clarify, I removed the following line from the DependsOn property of the Network Interface resource:

"[concat('Microsoft.Network/virtualNetworks/', 'other-resourcegroup-vnet')]"

This dependency was added as a result of me using the “Add Resource” dialog initiated by right-clicking the “resources” section of the Json Outline for my template in Visual Studio 2015.


Thursday, July 2, 2015 3:24 PM

Greetings!

Could you please share the parameters file (with non-sensitive data) for us to reference and guide you better.

Thank you,

Arvind


Thursday, July 2, 2015 4:12 PM

Hi Arvind,

Here is the parameters file:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "other-resourcegroup-vnetLocation": { "value": "South Central US" },
    "MyTestNicName": {"value": "TestNic1"}
  }
}

Wednesday, August 1, 2018 4:46 AM

This was very helpful! saved the day for us :) Thank you