|
1 | 1 | ---
|
2 | 2 | title: Configure cross-tenant connection in Azure Virtual Network Manager - PowerShell
|
3 |
| -description: #Required; article description that is displayed in search results. |
| 3 | +description: Learn to connect Azure subscriptions in Azure Virtual Network Manager using cross-tenant connections for the management of virtual networks across subscriptions using Azure PowerShell. |
4 | 4 | author: mbender-ms
|
5 | 5 | ms.author: mbender
|
6 | 6 | ms.service: virtual-network-manager
|
@@ -55,51 +55,84 @@ Set-AzContext -TenantId 12345678-12a3-4abc-5cde-678909876543
|
55 | 55 | Select-AzSubscription 87654321-abcd-1234-1def-0987654321ab
|
56 | 56 |
|
57 | 57 | #
|
58 |
| -New-AzNetworkManagerSubscriptionConnection -Name toContosoTenantNM -Description "This connection allows management of the tenant by a central management tenant" -NetworkManagerId "/subscriptions/13579864-1234-5678-abcd-0987654321ab/resourceGroups/$rg.name/providers/Microsoft.Network/networkManagers/"myAVNM"" |
| 58 | +New-AzNetworkManagerSubscriptionConnection -Name toCentralManagementTenant -Description "This connection allows management of the tenant by a central management tenant" -NetworkManagerId "/subscriptions/13579864-1234-5678-abcd-0987654321ab/resourceGroups/myAVNMResourceGroup/providers/Microsoft.Network/networkManagers/"myAVNM"" |
59 | 59 |
|
60 | 60 | #
|
61 |
| -Get-AzNetworkManagerSubscriptionConnection -Name toContosoTenantNM |
| 61 | +Get-AzNetworkManagerSubscriptionConnection -Name toCentralManagementTenant |
62 | 62 | ```
|
63 | 63 |
|
64 | 64 | ## Verify the connection state is ‘Connected’ (via grid item ‘Status’)
|
65 | 65 |
|
66 |
| -Switch back to the Contoso tenant, and performing a get on the network manager should show the subscription added via the cross tenant scopes property. |
| 66 | +Switch back to the central management tenant, and verify the subscription is added to the virtual network manager via the cross tenant scopes property. |
67 | 67 |
|
68 | 68 | ```azurepowershell
|
69 | 69 |
|
70 |
| -Get-AzNetworkManager -ResourceGroup $rg.name -Name "myAVN" |
| 70 | +Get-AzNetworkManager -ResourceGroup "myAVNMResourceGroup" -Name "myAVNM" |
71 | 71 |
|
72 | 72 | ```
|
73 | 73 |
|
74 | 74 | ## Generate auth tokens for PowerShell
|
75 |
| -From Azure Portal and Azure CLI we generate the auth tokens needed for the put static member request behind the scenes. Unfortunately, this is not possible (yet) via AVNM’s powershell cmdlets, so the tokens must be generated manually and the request must be sent via the ‘Invoke-RestMethod’ cmdlet |
| 75 | +For Azure Portal and Azure CLI, we generate the auth tokens needed for the put static member request behind the scenes. Unfortunately, this is not possible (yet) via AVNM’s pPowershell cmdlets, so the tokens must be generated manually and the request must be sent via the ‘Invoke-RestMethod’ cmdlet |
76 | 76 |
|
77 | 77 |
|
78 |
| -# Get the group you want to add the static members to |
79 |
| -$group = Get-AzNetworkManagerGroup -NetworkManagerName "myAVN" -ResourceGroup $rg.name -Name containsCrossTenantResources |
| 78 | +### Get the group you want to add the static members to |
| 79 | +$group = Get-AzNetworkManagerGroup -NetworkManagerName "myAVN" -ResourceGroup myAVNMResourceGroup -Name containsCrossTenantResources |
80 | 80 |
|
81 | 81 | # Need to be modified
|
| 82 | + |
| 83 | +```azurepowershell |
| 84 | +
|
82 | 85 | $networkManagerTenant = "24680975-1234-abcd-56fg-121314ab5643"
|
83 |
| -$vnetTenant = "12345678-12a3-4abc-5cde-678909876543" |
| 86 | +$targetTenant = "12345678-12a3-4abc-5cde-678909876543" |
84 | 87 | $staticMemberName = "crossTenantMember"
|
85 |
| -$vnetResourceId = “/subscriptions/795fe552-a2fc-466a-b436-de4520b73dd2/resourceGroups/temp/providers/Microsoft.Network/virtualNetworks/Vnet1” |
| 88 | +$targetResourceID = “/subscriptions/87654321-abcd-1234-1def-0987654321ab/resourceGroups/temp/providers/Microsoft.Network/virtualNetworks/targetVnet01” |
86 | 89 |
|
87 | 90 | # Everything after this can be copy/pasted
|
88 | 91 | $networkManagerToken = Get-AzAccessToken -TenantId $networkManagerTenant
|
89 |
| -$vnetToken = Get-AzAccessToken -TenantId $vnetTenant |
| 92 | +$targetToken = Get-AzAccessToken -TenantId $targetTenant |
90 | 93 |
|
91 | 94 | $authHeader = @{
|
92 | 95 | 'Content-Type'='application/json'
|
93 | 96 | 'Authorization'='Bearer ' + $networkManagerToken.Token
|
94 |
| - 'x-ms-authorization-auxiliary'='Bearer ' + $vnetToken.Token |
| 97 | + 'x-ms-authorization-auxiliary'='Bearer ' + $targetToken.Token |
95 | 98 | }
|
96 | 99 |
|
97 | 100 | $body = (@{
|
98 | 101 | ‘properties'= @{
|
99 |
| - 'resourceId'=$vnetResourceId |
| 102 | + 'resourceId'=$targetResourceID |
100 | 103 | }
|
101 | 104 | } | ConvertTo-Json)
|
102 | 105 |
|
103 | 106 | $restUri = "https://management.azure.com" + $group.Id + "/staticMembers/" + $staticMemberName + "?api-version=2022-01-01"
|
104 | 107 | Invoke-RestMethod -Uri $restUri -Method Put -Headers $authHeader -Body $body
|
105 | 108 |
|
| 109 | +``` |
| 110 | + |
| 111 | +## Delete virtual network manager configurations |
| 112 | + |
| 113 | +Now that the virtual network is in the network group, configurations will be applied. To remove the static member or cross-tenant resources, using the commands below: |
| 114 | + |
| 115 | +```azurepowershell |
| 116 | +
|
| 117 | +# delete connection on target managed tenant |
| 118 | +Remove-AzNetworkManagerScopeConnection -Name ToTargetManagedTenant -ResourceGroup "myAVNMResourceGroup" -NetworkManagerName "myAVNM" |
| 119 | +
|
| 120 | +# delete static member group |
| 121 | +Remove-AzNetworkManagerStaticMember -Name crossTenantMember -ResourceGroup "myAVNMResourceGroup" -NetworkManagerName "myAVNM"–NetworkGroupName containsCrossTenantResources |
| 122 | +
|
| 123 | +# Switch to ‘managed tenant’ if needed |
| 124 | +
|
| 125 | +# delete connection on central management tenant |
| 126 | +
|
| 127 | +Remove-AzNetworkManagerSubscriptionConnection -Name toCentralManagementTenant |
| 128 | +
|
| 129 | +``` |
| 130 | +## Next steps |
| 131 | + |
| 132 | +> [!div class="nextstepaction"] |
| 133 | +
|
| 134 | +- Learn more about [Security admin rules](concept-security-admins.md). |
| 135 | + |
| 136 | +- Learn how to [create a mesh network topology with Azure Virtual Network Manager using the Azure portal](how-to-create-mesh-network.md) |
| 137 | + |
| 138 | +- Check out the [Azure Virtual Network Manager FAQ](faq.md) |
0 commit comments