Skip to content

Instantly share code, notes, and snippets.

@krnese
Last active August 18, 2023 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krnese/a419eaab207913e325a5b0ece87cac13 to your computer and use it in GitHub Desktop.
Save krnese/a419eaab207913e325a5b0ece87cac13 to your computer and use it in GitHub Desktop.
VNet Peering of existing VNet
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vNetRgName": {
"type": "string",
"metadata": {
"description": "Provide a name for the resource group that will contain the virtual network."
}
},
"vNetName": {
"type": "string",
"metadata": {
"description": "Provide a name for the virtual network."
}
},
"vNetPeerUseRemoteGateway": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Use remote gateway or not."
}
},
"hubResourceId": {
"type": "string",
"metadata": {
"description": "Provide the resourceId for the hub."
},
"defaultValue": ""
}
},
"variables": {
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-06-01",
"name": "[concat('es-lz-vnet-',substring(uniqueString(subscription().id),0,6))]",
"resourceGroup": "[parameters('vNetRgName')]",
"dependsOn": [
],
"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": "2020-05-01",
"name": "[concat(parameters('vNetName'), '/peerToHub')]",
"dependsOn": [
],
"properties": {
"remoteVirtualNetwork": {
"id": "[parameters('hubResourceId')]"
},
"allowVirtualNetworkAccess": true,
"allowForwardedTraffic": true,
"allowGatewayTransit": true,
"useRemoteGateways": "[parameters('vNetPeerUseRemoteGateway')]"
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-06-01",
"name": "[concat('es-lz-hub-',substring(uniqueString(subscription().id),0,6),'-peering')]",
"subscriptionId": "[split(parameters('hubResourceId'),'/')[2]]",
"resourceGroup": "[split(parameters('hubResourceId'),'/')[4]]",
"dependsOn": [
],
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"remoteVirtualNetwork": {
"value": "[concat(subscription().id,'/resourceGroups/',parameters('vNetRgName'), '/providers/','Microsoft.Network/virtualNetworks/', parameters('vNetName'))]"
},
"hubName": {
"value": "[split(parameters('hubResourceId'),'/')[8]]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"remoteVirtualNetwork": {
"type": "String",
"defaultValue": false
},
"hubName": {
"type": "String",
"defaultValue": false
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
"name": "[[concat(parameters('hubName'),'/',last(split(parameters('remoteVirtualNetwork'),'/')))]",
"apiVersion": "2020-05-01",
"properties": {
"allowVirtualNetworkAccess": true,
"allowForwardedTraffic": true,
"allowGatewayTransit": true,
"useRemoteGateways": false,
"remoteVirtualNetwork": {
"id": "[[parameters('remoteVirtualNetwork')]"
}
}
}
],
"outputs": {}
}
}
}
],
"outputs": {}
}
}
}
],
"outputs": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment