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