You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -42,18 +42,22 @@ Install the latest *Az.Network* Azure PowerShell module using this command:
42
42
Before you can create an Azure Virtual Network Manager, you have to create a resource group to host the Network Manager. Create a resource group with [New-AzResourceGroup](/powershell/module/az.Resources/New-azResourceGroup). This example creates a resource group named **myAVNMResourceGroup** in the **WestUS** location.
43
43
44
44
```azurepowershell-interactive
45
+
46
+
$location = "West US"
45
47
$rg = @{
46
48
Name = 'myAVNMResourceGroup'
47
-
Location = 'WestUS'
49
+
Location = $location
48
50
}
49
-
New-AzResourceGroup @rg
51
+
New-AzResourceGroup $rg
52
+
50
53
```
51
54
52
55
## Create Virtual Network Manager
53
56
54
57
1. Define the scope and access type this Azure Virtual Network Manager instance will have. You can choose to create the scope with subscriptions group or management group or a combination of both. Create the scope by using New-AzNetworkManagerScope.
1. Create the Virtual Network Manager with New-AzNetworkManager. This example creates an Azure Virtual Network Manager named **myAVNM** in the West US location.
72
-
77
+
73
78
```azurepowershell-interactive
74
79
$avnm = @{
75
80
Name = 'myAVNM'
76
-
ResourceGroupName = 'myAVNMResourceGroup'
81
+
ResourceGroupName = $rg.Name
77
82
NetworkManagerScope = $scope
78
83
NetworkManagerScopeAccess = $access
79
-
Location = 'West US'
84
+
Location = $location
80
85
}
81
86
$networkmanager = New-AzNetworkManager @avnm
82
87
```
@@ -89,31 +94,32 @@ Create three virtual networks with [New-AzVirtualNetwork](/powershell/module/az.
89
94
$vnetA = @{
90
95
Name = 'VNetA'
91
96
ResourceGroupName = 'myAVNMResourceGroup'
92
-
Location = 'West US'
97
+
Location = $location
93
98
AddressPrefix = '10.0.0.0/16'
94
99
}
100
+
95
101
$virtualNetworkA = New-AzVirtualNetwork @vnetA
96
102
97
103
$vnetB = @{
98
104
Name = 'VNetB'
99
105
ResourceGroupName = 'myAVNMResourceGroup'
100
-
Location = 'West US'
106
+
Location = $location
101
107
AddressPrefix = '10.1.0.0/16'
102
108
}
103
109
$virtualNetworkB = New-AzVirtualNetwork @vnetB
104
110
105
111
$vnetC = @{
106
112
Name = 'VNetC'
107
113
ResourceGroupName = 'myAVNMResourceGroup'
108
-
Location = 'West US'
114
+
Location = $location
109
115
AddressPrefix = '10.2.0.0/16'
110
116
}
111
117
$virtualNetworkC = New-AzVirtualNetwork @vnetC
112
118
```
113
119
114
120
### Add a subnet to each virtual network
115
121
116
-
To complete the configuration of the virtual networks add a /24 subnet to each one. Create a subnet configuration named **default** with [Add-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/add-azvirtualnetworksubnetconfig).
122
+
To complete the configuration of the virtual networks, add a /24 subnet to each one. Create a subnet configuration named **default** with [Add-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/add-azvirtualnetworksubnetconfig).
1. Create a static virtual network member with New-AzNetworkManagerGroupMembersItem.
152
+
1. Create a network group to add virtual networks to.
149
153
150
154
```azurepowershell-interactive
151
155
$ng = @{
152
-
Name = 'myNetworkGroup'
153
-
ResourceGroupName = 'myAVNMResourceGroup'
154
-
NetworkManagerName = 'myAVNM'
155
-
MemberType = 'Microsoft.Network/VirtualNetwork'
156
-
}
157
-
$networkgroup = New-AzNetworkManagerGroup @ng
156
+
Name = 'myNetworkGroup'
157
+
ResourceGroupName = $rg.Name
158
+
NetworkManagerName = $networkManager.Name
159
+
}
160
+
$networkgroup = New-AzNetworkManagerGroup @ng
158
161
```
159
-
160
-
1. Add the static member to the static membership group with the following commands:
162
+
163
+
### Option 1: Static membership
161
164
165
+
166
+
1. Add the static member to the network group with the following commands:
167
+
1. Static members must have a network group scoped unique name. It's recommended to use a consistent hash of the virtual network ID. Below is an approach using the ARM Templates uniqueString() implementation.
1. Define the conditional statement and store it in a variable.
213
+
> [!NOTE]
214
+
> It is recommended to scope all of your conditionals to only scan for type `Microsoft.Network/virtualNetwork` for efficiency.
174
215
175
-
1. Define the conditional statement and store it in a variable:
216
+
```azurepowershell-interactive
217
+
$conditionalMembership = '{
218
+
"allof":[
219
+
{
220
+
"field": "type",
221
+
"equals": "Microsoft.Network/virtualNetwork"
222
+
}
223
+
{
224
+
"field": "name",
225
+
"contains": "VNet"
226
+
}
227
+
]
228
+
}'
229
+
```
230
+
231
+
1. Create the Azure Policy definition using the conditional statement defined in the last step using New-AzPolicyDefinition.
176
232
177
-
```azurepowershell-interactive
178
-
$conditionalMembership = '{
179
-
"allof":[
180
-
{
181
-
"field": "name",
182
-
"contains": "VNet"
183
-
}
184
-
]
185
-
}'
186
-
```
233
+
> [!IMPORTANT]
234
+
> Policy resources must have a scope unique name. It is recommended to use a consistent hash of the network group. Below is an approach using the ARM Templates uniqueString() implementation.
235
+
236
+
```azurepowershell-interactive
237
+
function Get-UniqueString ([string]$id, $length=13)
2. Remove the policy resources with Remove-AzPolicy*
348
+
349
+
```azurepowershell-interactive
350
+
351
+
Remove-AzPolicyAssignment $policyAssignment.Id
352
+
Remove-AzPolicyAssignment $policyDefinition.Id
353
+
286
354
```
287
355
288
-
1. Remove the network group with Remove-AzNetworkManagerGroup.
356
+
3. Remove the network group with Remove-AzNetworkManagerGroup.
289
357
290
358
```azurepowershell-interactive
291
-
$removegroup = @{
292
-
Name = 'myNetworkGroup'
293
-
ResourceGroupName = 'myAVNMResourceGroup'
294
-
NetworkManagerName = 'myAVNM'
295
-
}
296
-
Remove-AzNetworkManagerGroup @removegroup
359
+
Remove-AzNetworkManagerGroup $networkGroup.Id
297
360
```
298
361
299
-
1. Delete the network manager instance with Remove-AzNetworkManager.
362
+
4. Delete the network manager instance with Remove-AzNetworkManager.
300
363
301
364
```azurepowershell-interactive
302
-
$removenetworkmanager = @{
303
-
Name = 'myAVNM'
304
-
ResourceGroupName = 'myAVNMResourceGroup'
305
-
}
306
-
Remove-AzNetworkManager @removenetworkmanager
365
+
Remove-AzNetworkManager $networkManager.Id
307
366
```
308
367
309
-
1. If you no longer need the resource created, delete the resource group with [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup).
368
+
5. If you no longer need the resource created, delete the resource group with [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup).
0 commit comments