I need to add a subnet to a VNET in another resource group. I have an arm template (below) which adds a subnet to an existing resource group and it works okay but I need this subnet to be added to a VNET in another resource group.
example - there are 2 resource groups Resource Group A - Contains the VNET Resource Group B - VM deployed here but needs to connect to VNET in Resource Group A
When I deploy the template which created the VM to Resource Group B, i need to reference resource group A from within this ARM template, how can I do this? I am deploying via Visual Studio at the moment so I am using right click then Deploy to and selecting the resource group where the VM is being deployed to eg Resource Group B. The below code works but it deploys to the wrong resource group, it should add the subnet to Resource group where the VNET is but adds it to the resource group the VM is being deployed to!
"vnetID": "[resourceId(parameters('ResourceGroupName'),'Microsoft.Network/virtualNetworks',parameters('existingVNETName'))]"
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/virtualNetworks/subnets",
"name": "[concat(parameters('existingVNETName'), '/', parameters('newSubnetName'))]",
"location": "[resourceGroup().location]",
"properties": {
"addressPrefix": "[parameters('newSubnetAddressPrefix')]"