0
votes

Resource group=A

Resource group=B

A has a Vnet

B trying to create a subnet under A's Vnet

Tried using the below code, but it is failing

{
    "apiVersion": "2018-04-01",
    "comments": "AppGatewaySubnet_Creation",
    "dependsOn": [
        //"[resourceId('Microsoft.Network/virtualNetworks', parameters('VNET_Name'))]"
        //"[resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name'))]"
    ],
    "type": "Microsoft.Network/virtualNetworks/subnets",
    "name": "[concat(parameters('virtualNetworkName'), '/', parameters('subnetNameAppgateway'))]",
    "location": "[parameters('location')]",
    "properties": {
      "addressPrefix": "[parameters('subnetNameAppgatewayaddressPrefix')]"
    }
}
1
I would like to know why you are attempting to do this? What is the end goal of such a deployment, maybe there is another way to accomplish what you are ultimately trying to do.Ken W MSFT
We have a structured way of deploying infra on Azure. Vnet will be in resource group A and the appgateway will be in resource group B. So I would need to deploy appgateway whose subnet and vnet is referrenced from resource group A. This is the reason I am doing such deployments. Can you let me know the other way which you have mentioned in your comment? Thanks!Vikram

1 Answers

0
votes

you cannot do that, subnets belong to the vnet so they have to be in the same resource group. you can create them using cross resource group deployment.

Reading: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-cross-resource-group-deployment

so you'd need to create a deployment to A resource group as part of your deployment and make it deploy the subnet into the existing vnet

Example: https://github.com/Azure/azure-quickstart-templates/blob/master/101-subnet-add-vnet-existing/azuredeploy.json