2
votes

I am trying to create a NIC for a VM in a resource group. The problem I have is that i'm trying to reference a subnet from another resource group in Azure. Therefore, I am having to reference it using subscription level deployments in ARM templates.

"subnetref": "[concat(subscription().id, '/resourceGroups/', parameters('HUB Network RG'), '/providers/Microsoft.Network/virtualNetworks/', parameters('HUB VNet'), '/virtualNetworks/subnets', parameters('HUB DC Subnet'))]"

Above is the subnet ref variable I am trying to create. I then have the below for the VM NIC i'm trying to create.

{
    "type": "Microsoft.Network/networkInterfaces",
    "name": "[variables('nicnamedc1')]",
    "location": "[variables('location')]",
    "apiVersion": "2018-10-01",
    "properties": {
        "ipConfigurations": [
            {
                "name": "ipconfig1",
                "properties": {
                    "privateIPAllocationMethod": "Dynamic",
                    "subnet": {
                        "id": "[variables('subnetRef')]"
                    }
                }
            }
        ]
    }
},

I then get the below error.

New-AzDeployment : 14:54:23 - Resource Microsoft.Network/networkInterfaces 'before-nic' failed with message '{ "error": { "code": "InvalidRequestFormat", "message": "Cannot parse the request.", "details": [ { "code": "InvalidJsonReferenceFormat", "message": "Reference Id /subscriptions/404422c0-743d-4459-9db0-01892d0c7348/resourceGroups/hu b-network-rg/providers/Microsoft.Network/virtualNetworks/bsrgh-hub-vnetvirtualNetworks/subnetsdomain is not formatted correctly. The Id is expected to reference resources of type virtualNetworks/subnets. Path properties.ipConfigurations[0].properties.subnet."

I think it is complaining about the format that I've done the subnetref variable at the top. Is there a better way of doing this or am I going wrong somewhere?

1

1 Answers

3
votes

you forgot the / in your code:

"subnetref": "[concat(subscription().id, '/resourceGroups/', parameters('HUB Network RG'), '/providers/Microsoft.Network/virtualNetworks/', parameters('HUB VNet'), '/virtualNetworks/subnets/', parameters('HUB DC Subnet'))]"

but you are better of using resourceId() function:

resourceId(parameters('HUB Network RG'), 'Microsoft.Network/virtualNetworks/subnets', parameters('HUB VNet'), parameters('HUB DC Subnet'))

its a lot shorter and less error prone