Skip to content

Commit 62878e2

Browse files
author
Michael Bender
committed
Updates based on naming convention and added tabs
1 parent 139fa02 commit 62878e2

File tree

1 file changed

+110
-90
lines changed

1 file changed

+110
-90
lines changed

articles/virtual-network-manager/create-virtual-network-manager-powershell.md

Lines changed: 110 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ author: mbender-ms
55
ms.author: mbender
66
ms.service: virtual-network-manager
77
ms.topic: quickstart
8-
ms.date: 03/15/2023
9-
ms.custom: template-quickstart, ignite-fall-2021, mode-api
8+
ms.date: 04/12/2023
9+
ms.custom: template-quickstart, ignite-fall-2021, mode-api, engagement-fy23
1010
---
1111

1212
# Quickstart: Create a mesh network with Azure Virtual Network Manager using Azure PowerShell
@@ -25,143 +25,160 @@ In this quickstart, you deploy three virtual networks and use Azure Virtual Netw
2525
## Prerequisites
2626

2727
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
28-
* Run `Connect-AzAccount` to create a local connection with Azure.
2928

3029
> [!IMPORTANT]
31-
> Perform this quickstart using Powershell locally, not through Azure Cloud Shell. The version of `Az.Network` in Azure Cloud Shell does not currently support the Azure Virtual Network Manager cmdlets.
30+
> Perform this quickstart using PowerShell locally, not through Azure Cloud Shell. The version of `Az.Network` in Azure Cloud Shell does not currently support the Azure Virtual Network Manager cmdlets.
3231
32+
## Sign in to your Azure account and select your subscription
33+
34+
To begin your configuration, sign in to your Azure account. Use the following examples to help you connect:
35+
36+
Login to Azure
37+
38+
```azurepowershell
39+
Connect-AzAccount
40+
```
41+
42+
Connect to your subscription
43+
44+
```azurepowershell
45+
Set-AzContext -Subscription <subscription name or id>
46+
```
3347
## Install Azure PowerShell module
3448

3549
Install the latest *Az.Network* Azure PowerShell module using this command:
3650

3751
```azurepowershell-interactive
3852
Install-Module -Name Az.Network -RequiredVersion 5.3.0
3953
```
40-
4154
## Create a resource group
4255

43-
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.
56+
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 **vnm-learn-eastus-001ResourceGroup** in the **WestUS** location.
4457

4558
```azurepowershell-interactive
4659
47-
$location = "West US"
60+
$location = "East US"
4861
$rg = @{
49-
Name = 'myAVNMResourceGroup'
62+
Name = 'rg-learn-eastus-001'
5063
Location = $location
5164
}
5265
New-AzResourceGroup @rg
5366
5467
```
5568

56-
## Create Virtual Network Manager
69+
## Define the scope and access type
5770

58-
1. Define the scope and access type this Azure Virtual Network Manager instance 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.
71+
Define the scope and access type for the Azure Virtual Network Manager instance with [New-AzNetworkManagerScope](/powershell/module/az.network/new-aznetworkmanagerscope) This example defines a scope with a single subscription and sets the access type to **Connectivity**. Replace **<subscription id>** with the subscription ID of the subscription you want to manage with Azure Virtual Network Manager.
5972

60-
```azurepowershell-interactive
61-
62-
Import-Module -Name Az.Network -RequiredVersion "4.15.1"
63-
64-
[System.Collections.Generic.List[string]]$subGroup = @()
65-
$subGroup.Add("/subscriptions/abcdef12-3456-7890-abcd-ef1234567890")
66-
[System.Collections.Generic.List[string]]$mgGroup = @()
67-
$mgGroup.Add("/providers/Microsoft.Management/managementGroups/abcdef12-3456-7890-abcd-ef1234567890")
68-
69-
[System.Collections.Generic.List[String]]$access = @()
70-
$access.Add("Connectivity");
71-
$access.Add("SecurityAdmin");
72-
73-
$scope = New-AzNetworkManagerScope -Subscription $subGroup -ManagementGroup $mgGroup
74-
75-
```
73+
```azurepowershell-interactive
74+
75+
Import-Module -Name Az.Network -RequiredVersion "5.3.0"
76+
77+
[System.Collections.Generic.List[string]]$subGroup = @()
78+
$subGroup.Add("/subscriptions/<subscription id>")
79+
80+
[System.Collections.Generic.List[String]]$access = @()
81+
$access.Add("Connectivity");
82+
83+
$scope = New-AzNetworkManagerScope -Subscription $subGroup
7684
77-
1. Create the Virtual Network Manager with New-AzNetworkManager. This example creates an Azure Virtual Network Manager named **myAVNM** in the West US location.
85+
```
86+
## Create Virtual Network Manager
87+
88+
Create the Virtual Network Manager with [New-AzNetworkManager](/powershell/module/az.network/new-aznetworkmanager). This example creates an Azure Virtual Network Manager named **vnm-learn-eastus-001** in the East Us location.
7889

79-
```azurepowershell-interactive
80-
$avnm = @{
81-
Name = 'myAVNM'
82-
ResourceGroupName = $rg.Name
83-
NetworkManagerScope = $scope
84-
NetworkManagerScopeAccess = $access
85-
Location = $location
86-
}
87-
$networkmanager = New-AzNetworkManager @avnm
88-
```
90+
```azurepowershell-interactive
91+
$avnm = @{
92+
Name = 'vnm-learn-eastus-001'
93+
ResourceGroupName = $rg.Name
94+
NetworkManagerScope = $scope
95+
NetworkManagerScopeAccess = $access
96+
Location = $location
97+
}
98+
$networkmanager = New-AzNetworkManager @avnm
99+
```
89100

90101
## Create three virtual networks
91102

92-
Create three virtual networks with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork). This example creates virtual networks named **VNetA**, **VNetB** and **VNetC** in the **West US** location. If you already have virtual networks you want create a mesh network with, you can skip to the next section.
103+
Create three virtual networks with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork). This example creates virtual networks named **vnet-learn-prod-eastus-001**, **vnet-learn-prod-eastus-002** and **vnet-learn-test-eastus-003** in the **East Us** location. If you already have virtual networks you want create a mesh network with, you can skip to the next section.
93104

94105
```azurepowershell-interactive
95-
$vnetA = @{
96-
Name = 'VNetA'
97-
ResourceGroupName = 'myAVNMResourceGroup'
106+
$vnet001 = @{
107+
Name = 'vnet-learn-prod-eastus-001'
108+
ResourceGroupName = $rg.Name
98109
Location = $location
99110
AddressPrefix = '10.0.0.0/16'
100111
}
101112
102-
$virtualNetworkA = New-AzVirtualNetwork @vnetA
113+
$vnet_learn_prod_eastus_001 = New-AzVirtualNetwork @vnet001
103114
104-
$vnetB = @{
105-
Name = 'VNetB'
106-
ResourceGroupName = 'myAVNMResourceGroup'
115+
$vnet002 = @{
116+
Name = 'vnet-learn-prod-eastus-002'
117+
ResourceGroupName = $rg.Name
107118
Location = $location
108119
AddressPrefix = '10.1.0.0/16'
109120
}
110-
$virtualNetworkB = New-AzVirtualNetwork @vnetB
121+
$vnet_learn_prod_eastus_002 = New-AzVirtualNetwork @vnet002
111122
112-
$vnetC = @{
113-
Name = 'VNetC'
114-
ResourceGroupName = 'myAVNMResourceGroup'
123+
$vnet003 = @{
124+
Name = 'vnet-learn-test-eastus-003'
125+
ResourceGroupName = $rg.Name
115126
Location = $location
116127
AddressPrefix = '10.2.0.0/16'
117128
}
118-
$virtualNetworkC = New-AzVirtualNetwork @vnetC
129+
$vnet_learn_test_eastus_003 = New-AzVirtualNetwork @vnet003
119130
```
120131

121132
### Add a subnet to each virtual network
122133

123-
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).
134+
To complete the configuration of the virtual networks, create a subnet configuration named **default** with [Add-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/add-azvirtualnetworksubnetconfig) with a subnet address prefix of **/24**. Then, use [Set-AzVirtualNetwork](/powershell/module/az.network/set-azvirtualnetwork) to apply the subnet configuration to the virtual network.
124135

125136
```azurepowershell-interactive
126-
$subnetA = @{
137+
$subnet_vnet001 = @{
127138
Name = 'default'
128-
VirtualNetwork = $virtualNetworkA
139+
VirtualNetwork = $vnet_learn_prod_eastus_001
129140
AddressPrefix = '10.0.0.0/24'
130141
}
131-
$subnetConfigA = Add-AzVirtualNetworkSubnetConfig @subnetA
132-
$virtualnetworkA | Set-AzVirtualNetwork
142+
$subnetConfig_vnet001 = Add-AzVirtualNetworkSubnetConfig @subnet_vnet001
143+
$vnet_learn_prod_eastus_001 | Set-AzVirtualNetwork
133144
134-
$subnetB = @{
145+
$subnet_vnet002 = @{
135146
Name = 'default'
136-
VirtualNetwork = $virtualNetworkB
147+
VirtualNetwork = $vnet_learn_prod_eastus_002
137148
AddressPrefix = '10.1.0.0/24'
138149
}
139-
$subnetConfigC = Add-AzVirtualNetworkSubnetConfig @subnetB
140-
$virtualnetworkB | Set-AzVirtualNetwork
150+
$subnetConfig_vnet002 = Add-AzVirtualNetworkSubnetConfig @subnet_vnet002
151+
$vnet_learn_prod_eastus_002 | Set-AzVirtualNetwork
141152
142-
$subnetC = @{
153+
$subnet_vnet003 = @{
143154
Name = 'default'
144-
VirtualNetwork = $virtualNetworkC
155+
VirtualNetwork = $vnet_learn_test_eastus_003
145156
AddressPrefix = '10.2.0.0/24'
146157
}
147-
$subnetConfigC = Add-AzVirtualNetworkSubnetConfig @subnetC
148-
$virtualnetworkC | Set-AzVirtualNetwork
158+
$subnetConfig_vnet003 = Add-AzVirtualNetworkSubnetConfig @subnet_vnet003
159+
$vnet_learn_test_eastus_003 | Set-AzVirtualNetwork
149160
```
150161

151162
## Create a network group
163+
Virtual Network Manager applies configurations to groups of VNets by placing them in network groups. Create a network group with [New-AzNetworkManagerGroup](/powershell/module/az.network/new-aznetworkmanagergroup). This example creates a network group named **ng-learn-prod-eastus-001** in the **East Us** location.
164+
165+
```azurepowershell-interactive
166+
$ng = @{
167+
Name = 'ng-learn-prod-eastus-001'
168+
ResourceGroupName = $rg.Name
169+
NetworkManagerName = $networkManager.Name
170+
}
171+
$ng = New-AzNetworkManagerGroup @ng
172+
```
152173

153-
1. Create a network group to add virtual networks to.
174+
## Define membership for a mesh configuration
154175

155-
```azurepowershell-interactive
156-
$ng = @{
157-
Name = 'myNetworkGroup'
158-
ResourceGroupName = $rg.Name
159-
NetworkManagerName = $networkManager.Name
160-
}
161-
$networkgroup = New-AzNetworkManagerGroup @ng
162-
```
163-
164-
### Option 1: Static membership
176+
Once your network group is created, you define a network group's membership by adding virtual networks. Choose one of the options: *[Manually add membership](#manually-add-membership)* or *[Create policy to dynamically add members](#create-azure-policy-for-dynamic-membership)* with Azure Policy.
177+
# [Manual membership](#tab/manualmembership)
178+
179+
### Manually add membership
180+
181+
In this task, you manually add two virtual networks for your Mesh configuration to your network group using these steps:
165182

166183
1. Add the static member to the network group with the following commands:
167184
1. Static members must have a network group scoped unique name. It's recommended to use a consistent hash of the virtual network ID. This is an approach using the ARM Templates uniqueString() implementation.
@@ -176,22 +193,22 @@ $virtualnetworkC | Set-AzVirtualNetwork
176193
177194
```azurepowershell-interactive
178195
$smA = @{
179-
Name = Get-UniqueString $virtualNetworkA.Id
196+
Name = Get-UniqueString $vnet_learn_prod_eastus_001.Id
180197
ResourceGroupName = $rg.Name
181-
NetworkGroupName = $networkGroup.Name
198+
NetworkGroupName = ng.Name
182199
NetworkManagerName = $networkManager.Name
183-
ResourceId = $virtualNetworkA.Id
200+
ResourceId = $vnet_learn_prod_eastus_001.Id
184201
}
185202
$statimemberA = New-AzNetworkManagerStaticMember @sm
186203
```
187204
188205
```azurepowershell-interactive
189206
$smB = @{
190-
Name = Get-UniqueString $virtualNetworkB.Id
207+
Name = Get-UniqueString $vnet_learn_prod_eastus_002.Id
191208
ResourceGroupName = $rg.Name
192-
NetworkGroupName = $networkGroup.Name
209+
NetworkGroupName = ng.Name
193210
NetworkManagerName = $networkManager.Name
194-
ResourceId = $virtualNetworkB.Id
211+
ResourceId = $vnet_learn_prod_eastus_002.Id
195212
}
196213
$statimemberB = New-AzNetworkManagerStaticMember @sm
197214
```
@@ -200,14 +217,17 @@ $virtualnetworkC | Set-AzVirtualNetwork
200217
$smC = @{
201218
Name = Get-UniqueString $virtualNetworkC.Id
202219
ResourceGroupName = $rg.Name
203-
NetworkGroupName = $networkGroup.Name
220+
NetworkGroupName = ng.Name
204221
NetworkManagerName = $networkManager.Name
205222
ResourceId = $virtualNetworkC.Id
206223
}
207224
$statimemberC = New-AzNetworkManagerStaticMember @sm
208225
```
209226
210-
### Option 2: Dynamic membership
227+
# [Azure Policy](#tab/azurepolicy)
228+
### Create Azure Policy for dynamic membership
229+
230+
Using [Azure Policy](concept-azure-policy-integration.md), you define a condition to dynamically add two virtual networks to your network group when the name of the virtual network includes **prod** using these steps:
211231
212232
1. Define the conditional statement and store it in a variable.
213233
> [!NOTE]
@@ -243,7 +263,7 @@ $virtualnetworkC | Set-AzVirtualNetwork
243263

244264
```azurepowershell-interactive
245265
$defn = @{
246-
Name = Get-UniqueString $networkgroup.Id
266+
Name = Get-UniqueString ng.Id
247267
Mode = 'Microsoft.Network.Data'
248268
Policy = $conditionalMembership
249269
}
@@ -255,20 +275,20 @@ $virtualnetworkC | Set-AzVirtualNetwork
255275

256276
```azurepowershell-interactive
257277
$assgn = @{
258-
Name = Get-UniqueString $networkgroup.Id
278+
Name = Get-UniqueString ng.Id
259279
PolicyDefinition = $policyDefinition
260280
}
261281
262282
$policyAssignment = New-AzPolicyAssignment @assgn
263283
```
264-
284+
---
265285
## Create a configuration
266286
267287
1. Create a connectivity group item to add a network group to with New-AzNetworkManagerConnectivityGroupItem.
268288
269289
```azurepowershell-interactive
270290
$gi = @{
271-
NetworkGroupId = $networkgroup.Id
291+
NetworkGroupId = ng.Id
272292
}
273293
$groupItem = New-AzNetworkManagerConnectivityGroupItem @gi
274294
```
@@ -328,8 +348,8 @@ If you no longer need the Azure Virtual Network Manager, you need to make sure a
328348
[System.Collections.Generic.List[string]]$target = @()
329349
$target.Add("westus")
330350
$removedeployment = @{
331-
Name = 'myAVNM'
332-
ResourceGroupName = 'myAVNMResourceGroup'
351+
Name = 'vnm-learn-eastus-001'
352+
ResourceGroupName = $rg.Name
333353
ConfigurationId = $configIds
334354
Target = $target
335355
CommitType = 'Connectivity'
@@ -356,7 +376,7 @@ If you no longer need the Azure Virtual Network Manager, you need to make sure a
356376
3. Remove the network group with Remove-AzNetworkManagerGroup.
357377
358378
```azurepowershell-interactive
359-
Remove-AzNetworkManagerGroup $networkGroup.Id
379+
Remove-AzNetworkManagerGroup ng.Id
360380
```
361381
362382
4. Delete the network manager instance with Remove-AzNetworkManager.
@@ -368,7 +388,7 @@ If you no longer need the Azure Virtual Network Manager, you need to make sure a
368388
5. If you no longer need the resource created, delete the resource group with [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup).
369389
370390
```azurepowershell-interactive
371-
Remove-AzResourceGroup -Name 'myAVNMResourceGroup'
391+
Remove-AzResourceGroup -Name $rg.Name
372392
```
373393
374394
## Next steps

0 commit comments

Comments
 (0)