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?