Bicep を使用した Azure Virtual Network Manager の利用を開始して、すべての仮想ネットワークの接続を管理します。
このクイックスタートでは、3 つの仮想ネットワークをデプロイし、Azure Virtual Network Manager を使用してメッシュ ネットワーク トポロジを作成します。 次に、接続構成が適用されたことを確認します。
Bicep ファイル モジュール
このサンプルの Bicep ソリューションは、リソース グループとサブスクリプション スコープの両方でデプロイを有効にするためのモジュールに分かれています。 以下で詳しく説明するファイル セクションは、Virtual Network Manager の固有のコンポーネントです。 以下で詳しく説明されるセクションに加えて、このソリューションは仮想ネットワーク、ユーザー割り当て ID、ロールの割り当てもデプロイします。
Virtual Network Manager、ネットワーク グループ、接続構成
仮想ネットワーク マネージャー
@description('This is the Azure Virtual Network Manager which will be used to implement the connected group for inter-vnet connectivity.')
resource networkManager 'Microsoft.Network/networkManagers@2022-09-01' = {
name: 'vnm-learn-prod-${location}-001'
location: location
properties: {
networkManagerScopeAccesses: [
'Connectivity'
]
networkManagerScopes: {
subscriptions: [
'/subscriptions/${subscription().subscriptionId}'
]
managementGroups: []
}
}
}
ネットワーク グループ
このソリューションでは、静的メンバーシップ ネットワーク グループまたは動的メンバーシップ ネットワーク グループどちらかの作成がサポートされています。 静的メンバーシップ ネットワーク グループは、仮想ネットワーク ID でメンバーを指定します
静的メンバーシップ ネットワーク グループ
@description('This is the static network group for the all VNETs.')
resource networkGroupSpokesStatic 'Microsoft.Network/networkManagers/networkGroups@2022-09-01' = if (networkGroupMembershipType == 'static') {
name: 'ng-learn-prod-${location}-static001'
parent: networkManager
properties: {
description: 'Network Group - Static'
}
// add spoke vnets A, B, and C to the static network group
resource staticMemberSpoke 'staticMembers@2022-09-01' = [for spokeMember in spokeNetworkGroupMembers: if (contains(groupedVNETs,last(split(spokeMember,'/')))) {
name: 'sm-${(last(split(spokeMember, '/')))}'
properties: {
resourceId: spokeMember
}
}]
resource staticMemberHub 'staticMembers@2022-09-01' = {
name: 'sm-${(toLower(last(split(hubVnetId, '/'))))}'
properties: {
resourceId: hubVnetId
}
}
}
動的メンバーシップ ネットワーク グループ
@description('This is the dynamic group for all VNETs.')
resource networkGroupSpokesDynamic 'Microsoft.Network/networkManagers/networkGroups@2022-09-01' = if (networkGroupMembershipType == 'dynamic') {
name: 'ng-learn-prod-${location}-dynamic001'
parent: networkManager
properties: {
description: 'Network Group - Dynamic'
}
}
接続構成
接続構成は、ネットワーク グループを指定したネットワーク トポロジに関連付けます。
@description('This connectivity configuration defines the connectivity between VNETs using Direct Connection. The hub will be part of the mesh, but gateway routes from the hub will not propagate to spokes.')
resource connectivityConfigurationMesh 'Microsoft.Network/networkManagers/connectivityConfigurations@2022-09-01' = {
name: 'cc-learn-prod-${location}-mesh001'
parent: networkManager
properties: {
description: 'Mesh connectivity configuration'
appliesToGroups: [
{
networkGroupId: (networkGroupMembershipType == 'static') ? networkGroupSpokesStatic.id : networkGroupSpokesDynamic.id
isGlobal: 'False'
useHubGateway: 'False'
groupConnectivity: 'DirectlyConnected'
}
]
connectivityTopology: 'Mesh'
deleteExistingPeering: 'True'
hubs: []
isGlobal: 'False'
}
}
配置スクリプト
構成をターゲット ネットワーク グループにデプロイするための、Deploy-AzNetworkManagerCommit
PowerShell コマンドの呼び出しのためにデプロイ スクリプトが使用されます。 デプロイ スクリプトには、Virtual Network Manager に対して PowerShell スクリプトを実行するための十分なアクセス許可を持つ ID が必要です。そのため、Bicep ファイルによってユーザー マネージド ID が作成され、ターゲット リソース グループに対する "共同作成者" ロールが付与されます。 デプロイ スクリプトと関連する ID の詳細については、「ARM テンプレートでデプロイ スクリプトを使用する」を参照してください。
@description('Create a Deployment Script resource to perform the commit/deployment of the Network Manager connectivity configuration.')
resource deploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: deploymentScriptName
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${userAssignedIdentityId}': {}
}
}
properties: {
azPowerShellVersion: '8.3'
retentionInterval: 'PT1H'
timeout: 'PT1H'
arguments: '-networkManagerName "${networkManagerName}" -targetLocations ${location} -configIds ${configurationId} -subscriptionId ${subscription().subscriptionId} -configType ${configType} -resourceGroupName ${resourceGroup().name}'
scriptContent: '''
param (
# AVNM subscription id
[parameter(mandatory=$true)][string]$subscriptionId,
# AVNM resource name
[parameter(mandatory=$true)][string]$networkManagerName,
# string with comma-separated list of config ids to deploy. ids must be of the same config type
[parameter(mandatory=$true)][string[]]$configIds,
# string with comma-separated list of deployment target regions
[parameter(mandatory=$true)][string[]]$targetLocations,
# configuration type to deploy. must be either connectivity or securityadmin
[parameter(mandatory=$true)][ValidateSet('Connectivity','SecurityAdmin')][string]$configType,
# AVNM resource group name
[parameter(mandatory=$true)][string]$resourceGroupName
)
$null = Login-AzAccount -Identity -Subscription $subscriptionId
[System.Collections.Generic.List[string]]$configIdList = @()
$configIdList.addRange($configIds)
[System.Collections.Generic.List[string]]$targetLocationList = @() # target locations for deployment
$targetLocationList.addRange($targetLocations)
$deployment = @{
Name = $networkManagerName
ResourceGroupName = $resourceGroupName
ConfigurationId = $configIdList
TargetLocation = $targetLocationList
CommitType = $configType
}
try {
Deploy-AzNetworkManagerCommit @deployment -ErrorAction Stop
}
catch {
Write-Error "Deployment failed with error: $_"
throw "Deployment failed with error: $_"
}
'''
}
}
動的ネットワーク グループ メンバーシップ ポリシー
デプロイが dynamic
ネットワーク グループ メンバーシップを使用するように構成されている場合、このソリューションは Azure ポリシー定義と割り当てもデプロイします。 ポリシー定義を次に示します。
@description('This is a Policy definition for dynamic group membership')
resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2021-06-01' = {
name: uniqueString(networkGroupId)
properties: {
description: 'AVNM quickstart dynamic group membership Policy'
displayName: 'AVNM quickstart dynamic group membership Policy'
mode: 'Microsoft.Network.Data'
policyRule: {
if: {
allof: [
{
field: 'type'
equals: 'Microsoft.Network/virtualNetworks'
}
{
// virtual networks must have a tag where the key is '_avnm_quickstart_deployment'
field: 'tags[_avnm_quickstart_deployment]'
exists: true
}
{
// virtual network ids must include this sample's resource group ID - limiting the chance that dynamic membership impacts other vnets in your subscriptions
field: 'id'
like: '${subscription().id}/resourcegroups/${resourceGroupName}/*'
}
]
}
then: {
// 'addToNetworkGroup' is a special effect used by AVNM network groups
effect: 'addToNetworkGroup'
details: {
networkGroupId: networkGroupId
}
}
}
}
}
Bicep ソリューションをデプロイする
デプロイの前提条件
- アクティブなサブスクリプションが含まれる Azure アカウント。 無料でアカウントを作成できます。
- ターゲット サブスクリプション スコープでポリシー定義とポリシー割り当てを作成するためのアクセス許可 (これは、デプロイ パラメーター
networkGroupMembershipType=Dynamic
を使用してネットワーク グループ メンバーシップに必要なポリシー リソースをデプロイするときに必要です)。 既定値はstatic
です。これはポリシーをデプロイしません。
Bicep ソリューションをダウンロードする
- このリンクにある MSPNP リポジトリの ZIP アーカイブをダウンロードします
- ダウンロードした ZIP ファイルを展開し、ターミナルで
solutions/avnm-mesh-connected-group/bicep
ディレクトリに移動します。
または、git
を使用して git clone https://github.com/mspnp/samples.git
でリポジトリを複製することもできます
Azure に接続する
Azure アカウントにサインインしてサブスクリプションを選択する
構成を始めるには、Azure アカウントにサインインします。
Connect-AzAccount
次に、サブスクリプションに接続します。
Set-AzContext -Subscription <subscription name or id>
Azure PowerShell モジュールのインストール
次のコマンドを使用して、最新の Az.Network Azure PowerShell モジュールをインストールします。
Install-Module -Name Az.Network -RequiredVersion 5.3.0
デプロイ パラメーター
- resourceGroupName: [必須] このパラメーターは、仮想ネットワーク マネージャーとサンプル仮想ネットワークがデプロイされるリソース グループの名前を指定します。
- location: [必須] このパラメーターは、デプロイするリソースの場所を指定します。
-
networkGroupMembershipType: [省略可能] このパラメーターは、デプロイするするネットワーク グループ メンバーシップの種類を指定します。 既定値は
static
ですが、dynamic
を指定することで動的グループ メンバーシップを使用できます。
注意
メンバーシップを管理するために動的グループ メンバーシップが Azure ポリシーをデプロイすることを選択すると、より多くのアクセス許可が必要になります。
$templateParameterObject = @{
'location' = '<resourceLocation>'
'resourceGroupName' = '<newOrExistingResourceGroup>'
}
New-AzSubscriptionDeployment -TemplateFile ./main.bicep -Location <deploymentLocation> -TemplateParameterObject $templateParameterObject
構成のデプロイを確認する
各仮想ネットワークの [ネットワーク マネージャー] セクションを使用して、構成をデプロイしたことを確認します。
vnet-learn-prod-{location}-spoke001 仮想ネットワークに移動します。
[設定] で [ネットワーク マネージャー] を選択します。
[接続構成] タブで、cc-learn-prod-{location}-mesh001 が一覧に表示されていることを確認します。
vnet-learn-prod-{location}-spoke004 で前の手順を繰り返します。vnet-learn-prod-{location}-spoke004 が接続構成から除外されていることが確認できるはずです。
リソースをクリーンアップする
Azure Virtual Network Manager や関連する仮想ネットワークが不要になった場合は、リソース グループとそのリソースを削除することで削除できます。
- Azure portal で、リソース グループ - resource-group を参照します。
- resource-group を選択し、[リソース グループの削除] を選択します。
- [リソース グループの削除] ウィンドウで、テキスト ボックスに「resource-group」と入力して削除することを確認し、[削除] を選択します。
-
動的ネットワーク グループ メンバーシップを使用した場合は、Portal でサブスクリプションに移動し、[ポリシー] を選択して、デプロイされた Azure ポリシー定義と割り当てを削除します。 [ポリシー] で、 という名前の
AVNM quickstart dynamic group membership Policy
を見つけて削除した後に、 という名前のAVNM quickstart dynamic group membership Policy
に対して同じ操作を行います。
次のステップ
Azure Virtual Network Manager インスタンスを作成したら、セキュリティ管理者の構成を使用してネットワーク トラフィックをブロックする方法について確認します。