Last active
April 28, 2021 09:42
-
-
Save krnese/fc72353eff1feddf2291093c012251da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": {}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Authorization/policyDefinitions", | |
"apiVersion": "2019-09-01", | |
"name": "vnet-dns", | |
"properties": { | |
"description": "This policy deploys virtual network and peer to the hub", | |
"displayName": "Deploys virtual network peering to hub", | |
"mode": "All", | |
"parameters": { | |
"vNetName": { | |
"type": "String", | |
"metadata": { | |
"displayName": "vNetName", | |
"description": "Name of the landing zone vNet" | |
} | |
}, | |
"vNetRgName": { | |
"type": "String", | |
"metadata": { | |
"displayName": "vNetRgName", | |
"description": "Name of the landing zone vNet RG" | |
} | |
}, | |
"vNetLocation": { | |
"type": "String", | |
"metadata": { | |
"displayName": "vNetLocation", | |
"description": "Location for the vNet" | |
} | |
}, | |
"vNetCidrRange": { | |
"type": "String", | |
"metadata": { | |
"displayName": "vNetCidrRange", | |
"description": "CIDR Range for the vNet" | |
} | |
}, | |
"hubResourceId": { | |
"type": "String", | |
"metadata": { | |
"displayName": "hubResourceId", | |
"description": "Resource ID for the HUB vNet" | |
} | |
}, | |
"dnsServerIp": { | |
"type": "Array", | |
"defaultValue": [], | |
"metadata": { | |
"displayName": "IP address of the DNS server", | |
"description": "Provide the IP address of the DNS server the vnet will use, or leave empty to use Azure DNS." | |
} | |
} | |
}, | |
"metadata": { | |
"version": "1.0.0", | |
"category": "Network" | |
}, | |
"policyRule": { | |
"if": { | |
"allOf": [ | |
{ | |
"field": "type", | |
"equals": "Microsoft.Resources/subscriptions" | |
} | |
] | |
}, | |
"then": { | |
"effect": "deployIfNotExists", | |
"details": { | |
"type": "Microsoft.Network/virtualNetworks", | |
"name": "[[parameters('vNetName')]", | |
"deploymentScope": "Subscription", | |
"existenceScope": "ResourceGroup", | |
"ResourceGroupName": "[[parameters('vNetRgName')]", | |
"roleDefinitionIds": [ | |
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c" | |
], | |
"existenceCondition": { | |
"allOf": [ | |
{ | |
"field": "name", | |
"like": "[[parameters('vNetName')]" | |
}, | |
{ | |
"field": "location", | |
"equals": "[[parameters('vNetLocation')]" | |
} | |
] | |
}, | |
"deployment": { | |
"location": "northeurope", | |
"properties": { | |
"mode": "Incremental", | |
"parameters": { | |
"vNetRgName": { | |
"value": "[[parameters('vNetRgName')]" | |
}, | |
"vNetName": { | |
"value": "[[parameters('vNetName')]" | |
}, | |
"vNetLocation": { | |
"value": "[[parameters('vNetLocation')]" | |
}, | |
"vNetCidrRange": { | |
"value": "[[parameters('vNetCidrRange')]" | |
}, | |
"hubResourceId": { | |
"value": "[[parameters('hubResourceId')]" | |
}, | |
"dnsServerIp": { | |
"value": "[[parameters('dnsServerIp')]" | |
} | |
}, | |
"template": { | |
"$schema": "http://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"vNetRgName": { | |
"type": "String" | |
}, | |
"vNetName": { | |
"type": "String" | |
}, | |
"vNetLocation": { | |
"type": "String" | |
}, | |
"vNetCidrRange": { | |
"type": "String" | |
}, | |
"vNetPeerUseRemoteGateway": { | |
"type": "bool", | |
"defaultValue": false | |
}, | |
"hubResourceId": { | |
"type": "String" | |
}, | |
"dnsServerIp": { | |
"type": "Array", | |
"defaultValue": [] | |
} | |
}, | |
"variables": { | |
"dnsConfig": { | |
"dnsServers": "[[parameters('dnsServerIp')]" | |
} | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Resources/deployments", | |
"apiVersion": "2020-06-01", | |
"name": "[[concat('es-lz-vnet-',substring(uniqueString(subscription().id),0,6),'-rg')]", | |
"location": "[[parameters('vNetLocation')]", | |
"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.Resources/resourceGroups", | |
"apiVersion": "2020-06-01", | |
"name": "[[parameters('vNetRgName')]", | |
"location": "[[parameters('vNetLocation')]", | |
"properties": {} | |
}, | |
{ | |
"type": "Microsoft.Resources/resourceGroups", | |
"apiVersion": "2020-06-01", | |
"name": "NetworkWatcherRG", | |
"location": "[[parameters('vNetLocation')]", | |
"properties": {} | |
} | |
], | |
"outputs": {} | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Resources/deployments", | |
"apiVersion": "2020-06-01", | |
"name": "[[concat('es-lz-vnet-',substring(uniqueString(subscription().id),0,6))]", | |
"dependsOn": [ | |
"[[concat('es-lz-vnet-',substring(uniqueString(subscription().id),0,6),'-rg')]" | |
], | |
"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", | |
"apiVersion": "2020-06-01", | |
"name": "[[parameters('vNetName')]", | |
"location": "[[parameters('vNetLocation')]", | |
"dependsOn": [], | |
"properties": { | |
"addressSpace": { | |
"addressPrefixes": [ | |
"[[parameters('vNetCidrRange')]" | |
] | |
}, | |
"dhcpOptions": "[[if(not(empty(parameters('dnsServerIp'))), variables('dnsConfig'), json('null'))]" | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings", | |
"apiVersion": "2020-05-01", | |
"name": "[[concat(parameters('vNetName'), '/peerToHub')]", | |
"dependsOn": [ | |
"[[parameters('vNetName')]" | |
], | |
"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": [ | |
"[[parameters('vNetName')]" | |
], | |
"properties": { | |
"mode": "Incremental", | |
"expressionEvaluationOptions": { | |
"scope": "inner" | |
}, | |
"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": {} | |
}, | |
"parameters": { | |
"remoteVirtualNetwork": { | |
"value": "[[concat(subscription().id,'/resourceGroups/',parameters('vNetRgName'), '/providers/','Microsoft.Network/virtualNetworks/', parameters('vNetName'))]" | |
}, | |
"hubName": { | |
"value": "[[split(parameters('hubResourceId'),'/')[8]]" | |
} | |
} | |
} | |
} | |
], | |
"outputs": {} | |
} | |
}, | |
"resourceGroup": "[[parameters('vNetRgName')]" | |
} | |
], | |
"outputs": {} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment