-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvnet-spoke.json
More file actions
142 lines (142 loc) · 5.46 KB
/
vnet-spoke.json
File metadata and controls
142 lines (142 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"peer": {
"type": "bool",
"allowedValues": [true, false],
"defaultValue": true
},
"hub": {
"type": "object",
"defaultValue": {
"resourceGroup": "armLab7.1",
"vnet": {
"name": "hubnet"
}
}
},
"spoke": {
"type": "object",
"defaultValue": {
"vnet": {
"name": "spokenet",
"addressPrefixes": ["10.20.0.0/16"]
},
"subnets": [
{"name": "frontEnd", "addressPrefix": "10.20.0.0/24"},
{"name": "backEnd", "addressPrefix": "10.20.1.0/24"}
]
}
}
},
"variables": {
"hubId": "[if(parameters('peer'), resourceId(parameters('hub').resourceGroup, 'Microsoft.Network/virtualNetworks/', parameters('hub').vnet.name), '')]",
"spokeId": "[resourceId('Microsoft.Network/virtualNetworks/', parameters('spoke').vnet.name)]",
"copy": [{
"name": "subnets",
"count": "[length(parameters('spoke').subnets)]",
"input": {
"name": "[parameters('spoke').subnets[copyIndex('subnets')].name]",
"addressPrefix": "[parameters('spoke').subnets[copyIndex('subnets')].addressPrefix]",
"id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', parameters('spoke').vnet.name), '/subnets/', parameters('spoke').subnets[copyIndex('subnets')].name)]"
}
}]
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2018-08-01",
"name": "[parameters('spoke').vnet.name]",
"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]"
}
}
}]
}
},
{
"condition": "[parameters('peer')]",
"name": "[concat(parameters('spoke').vnet.name, '/peering-to-', parameters('hub').vnet.name)]",
"type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
"apiVersion": "2019-04-01",
"location": "[resourceGroup().location]",
"dependsOn": [
"[variables('spokeId')]"
],
"properties": {
"allowVirtualNetworkAccess": true,
"allowForwardedTraffic": false,
"allowGatewayTransit": false,
"useRemoteGateways": false,
"remoteVirtualNetwork": {
"id": "[variables('hubId')]"
}
}
},
{
"condition": "[parameters('peer')]",
"name": "[concat('peer-', parameters('hub').vnet.name, '-to-', parameters('spoke').vnet.name)]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-05-01",
"resourceGroup": "[parameters('hub').resourceGroup]",
"dependsOn": [
"[variables('spokeId')]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"name": "[concat(parameters('hub').vnet.name, '/peering-to-', parameters('spoke').vnet.name)]",
"type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
"apiVersion": "2019-04-01",
"location": "[resourceGroup().location]",
"properties": {
"allowVirtualNetworkAccess": true,
"allowForwardedTraffic": false,
"allowGatewayTransit": false,
"useRemoteGateways": false,
"remoteVirtualNetwork": {
"id": "[variables('spokeId')]"
}
}
}
]
}
}
}
],
"outputs": {
"peer": {
"type": "bool",
"value": "[parameters('peer')]"
},
"hubId": {
"type": "string",
"value": "[variables('hubId')]"
},
"spokeId": {
"type": "string",
"value": "[variables('spokeId')]"
},
"subnets": {
"type": "array",
"value": "[variables('subnets')]"
}
}
}