Sanju
Sanju

Reputation: 3

Azure vnet cross subscription peering

I am trying to create spoke vnet in a new subscription and trying to peer with already existing hub vnet in another subscription via ARM template. What is the best way to do this? How do you reference the Hub vnet?

This is how I am referencing hub vnet and no luck:

{
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2017-05-10",
      "name": "nestedTemplate",
      "resourceGroup": "[parameters('secondResourceGroup')]",
      "subscriptionId": "[parameters('secondSubscriptionID')]",
      "properties": {
      "mode": "Incremental",
      "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
             "type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
                    "apiVersion": "2019-11-01",
                    "properties": {
                                "allowVirtualNetworkAccess": true,
                                "allowForwardedTraffic": true,
                                "allowGatewayTransit": true,
                                "useRemoteGateways": false,
                                "remoteVirtualNetwork": "r_name",
                                "remoteAddressSpace": {
                                "addressPrefixes": "CIDR_spcae"
                                }
          ]
      },

Upvotes: 0

Views: 1329

Answers (2)

Sanju
Sanju

Reputation: 3

I figures this one. The issue was wrong reference of parameters.

Upvotes: 0

Nancy Xiong
Nancy Xiong

Reputation: 28294

You can reference the hub VNet in a different subscription in the remoteVirtualNetwork parameter with its ID.

Here is a Sample, Replace <subscription ID> with another subscription ID.

{
     "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
     "contentVersion": "1.0.0.0",
     "parameters": {
     },
     "variables": {
     },
 "resources": [
         {
         "apiVersion": "2016-06-01",
         "type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
         "name": "myVnetA/myVnetAToMyVnetB",
         "location": "[resourceGroup().location]",
         "properties": {
         "allowVirtualNetworkAccess": true,
         "allowForwardedTraffic": false,
         "allowGatewayTransit": false,
         "useRemoteGateways": false,
             "remoteVirtualNetwork": {
             "id": "/subscriptions/<subscription ID>/resourceGroups/PeeringTest/providers/Microsoft.Network/virtualNetworks/myVnetB"
             }
         }
         }
     ]
}

You also could get more details from this blog: Using ARM templates to create Azure Vnets, part 2: peering

Upvotes: 1

Related Questions