{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "peer": { "type": "bool", "defaultValue": true, "metadata": { "description": "Boolean to control whether spoke is peered to the hub" } }, "hub": { "type": "object", "defaultValue": { "resourceGroup": "westeurope", "vnet": { "name": "hub" } }, "metadata": { "description": "Object containing required information for the hub vNet. See defaultValue for minimum expected structure." } }, "spoke": { "type": "object", "defaultValue": { "vnet": { "name": "Example-vnet", "addressPrefixes": [ "10.1.0.0/16" ] }, "subnets": [ { "addressPrefix": "10.1.1.0/24", "name": "Example-vnet-subnet1" }, { "addressPrefix": "10.1.2.0/24", "name": "Example-vnet-subnet2" } ] }, "metadata": { "description": "Object containing information for the spoke vNet. See defaultValue for expected structure." } } }, "resources": [ { "name": "[concat(parameters('spoke').vnet.name)]", "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2017-10-01", "location": "[resourceGroup().location]", "properties": { "addressSpace": { "addressPrefixes": "[parameters('spoke').vnet.addressPrefixes]" }, "copy": [ { "name": "subnets", "count": "[length(parameters('spoke').subnets)]", "input": { "name": "[parameters('spoke').subnets[copyIndex('subnets')].name]", "properties": { "addressPrefix": "[parameters('spoke').subnets[copyIndex('subnets')].addressPrefix]" } } } ] } }, { "comments": "Optional vnet to hub peering", "condition": "[parameters('peer')]", "name": "[concat(parameters('spoke').vnet.name, '/to-', parameters('hub').vnet.name)]", "type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings", "apiVersion": "2017-10-01", "location": "[resourceGroup().location]", "properties": { "allowVirtualNetworkAccess": true, "allowForwardedTraffic": false, "allowGatewayTransit": false, "useRemoteGateways": false, "remoteVirtualNetwork": { "id": "[resourceId(parameters('hub').resourceGroup,'Microsoft.Network/virtualNetworks/', parameters('hub').vnet.name)]" } }, "dependsOn": [ "[concat(parameters('spoke').vnet.name)]" ] }, { "comments": "Inline deployment for reverse peering", "condition": "[parameters('peer')]", "name": "[concat('DeployVnetPeering-', parameters('hub').vnet.name, '-to-', parameters('spoke').vnet.name)]", "type": "Microsoft.Resources/deployments", "apiVersion": "2017-05-10", "resourceGroup": "[parameters('hub').resourceGroup]", "properties": { "mode": "Incremental", "template": { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "resources": [ { "apiVersion": "2017-10-01", "type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings", "name": "[concat(parameters('hub').vnet.name, '/to-', parameters('spoke').vnet.name)]", "location": "[resourceGroup().location]", "properties": { "allowVirtualNetworkAccess": true, "allowForwardedTraffic": false, "allowGatewayTransit": true, "useRemoteGateways": false, "remoteVirtualNetwork": { "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/', parameters('spoke').vnet.name)]" } } } ] } }, "dependsOn": [ "[concat(parameters('spoke').vnet.name)]" ] } ] }