0

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"
                                }
          ]
      },

halfer
  • 19,824
  • 17
  • 99
  • 186
Sanju
  • 3
  • 4

2 Answers2

1

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

Nancy
  • 26,865
  • 3
  • 18
  • 34
  • Thanks for responding Nancy ! I am getting the following error .Deployment template validation failed: 'The template resource 'test-peering--spoke' for type'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Common.Entities.TemplateGenericProperty`1[System.String]' at line '1' and column '545' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name. Please see https://aka.ms/arm-template/#resources for usage details.'. (Code: InvalidTemplate – Sanju Apr 03 '20 at 19:19
  • Could you display your full template? Or check the partition as the error show `A root resource type must have segment length one greater than its resource name.` – Nancy Apr 06 '20 at 09:59
0

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

Sanju
  • 3
  • 4