Skip to content

Commit b4583e9

Browse files
Added new properties NetworkIdentifier and ServiceEndpointConfig in Vnet/Subnet config for setting SNAT/VIP. (#25284)
* Added new property [-NetworkIdentifier <String>] on Subnet config * updated the type of SENetworkIdentifier from string to PSServiceEndpoint object * Added Fields to support networkidentifier * Added helper file for code refactoring and reusability * Added test Subnet Service Endpoint feature With NetworkIdentifier. * added tests for serviceendpoint with networkidentifier * Distinct to GroupBy fix. * space added --------- Co-authored-by: Bhupesh Bhatt <[email protected]>
1 parent 59ba3c4 commit b4583e9

13 files changed

+3524
-32
lines changed

src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ public void TestVirtualNetworkSubnetServiceEndpoint()
146146
TestRunner.RunTestScript("Test-VirtualNetworkSubnetServiceEndpoint");
147147
}
148148

149+
[Fact]
150+
[Trait(Category.AcceptanceType, Category.CheckIn)]
151+
[Trait(Category.Owner, NrpTeamAlias.wanrpdev_subset1)]
152+
public void TestVirtualNetworkSubnetServiceEndpointWithNetworkIdentifier()
153+
{
154+
TestRunner.RunTestScript("Test-VirtualNetworkSubnetServiceEndpointWithNetworkIdentifier");
155+
}
156+
157+
[Fact]
158+
[Trait(Category.AcceptanceType, Category.CheckIn)]
159+
[Trait(Category.Owner, NrpTeamAlias.wanrpdev_subset1)]
160+
public void TestVirtualNetworkSubnetServiceEndpointConfig()
161+
{
162+
TestRunner.RunTestScript("Test-VirtualNetworkSubnetServiceEndpointConfig");
163+
}
164+
149165
[Fact]
150166
[Trait(Category.AcceptanceType, Category.CheckIn)]
151167
[Trait(Category.Owner, NrpTeamAlias.wanrpdev_subset1)]

src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.ps1

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,115 @@ function Test-VirtualNetworkSubnetServiceEndpoint
12051205
}
12061206
}
12071207

1208+
<#
1209+
.SYNOPSIS
1210+
Tests checking Virtual Network Subnet Service Endpoint feature With NetworkIdentifier.
1211+
#>
1212+
function Test-VirtualNetworkSubnetServiceEndpointWithNetworkIdentifier
1213+
{
1214+
# Setup
1215+
$rgname = Get-ResourceGroupName
1216+
$vnetName = Get-ResourceName
1217+
$subnetName = Get-ResourceName
1218+
$rglocation = Get-ProviderLocation ResourceManagement
1219+
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
1220+
$location = Get-ProviderLocation $resourceTypeParent
1221+
$publicIPAddressName = "PublicIPAddressName";
1222+
$publicIPAddressAllocationMethod = "Static";
1223+
$serviceEndpoint = "Microsoft.Storage"
1224+
1225+
try
1226+
{
1227+
# Create the resource group
1228+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" };
1229+
1230+
# Create the publicip
1231+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIPAddressName -location $location -AllocationMethod $publicIPAddressAllocationMethod
1232+
1233+
# Create the $networkIdentifier
1234+
$networkIdentifier = @{ Id = $publicip.Id };
1235+
1236+
# Create the Virtual Network
1237+
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 -ServiceEndpoint $serviceEndpoint -NetworkIdentifier $networkIdentifier ;
1238+
New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet;
1239+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname;
1240+
1241+
Assert-NotNull $vnet;
1242+
Assert-NotNull $vnet.Subnets;
1243+
1244+
$subnet = $vnet.Subnets[0];
1245+
Assert-AreEqual $serviceEndpoint $subnet.serviceEndpoints[0].Service;
1246+
Assert-AreEqual $networkIdentifier.Id $subnet.serviceEndpoints[0].networkIdentifier.Id;
1247+
1248+
1249+
Set-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet -AddressPrefix 10.0.1.0/24 -ServiceEndpoint $null;
1250+
$vnet = Set-AzVirtualNetwork -VirtualNetwork $vnet;
1251+
$subnet = $vnet.Subnets[0];
1252+
1253+
Assert-Null $subnet.serviceEndpoints;
1254+
}
1255+
finally
1256+
{
1257+
# Cleanup
1258+
Clean-ResourceGroup $rgname
1259+
}
1260+
}
1261+
1262+
<#
1263+
.SYNOPSIS
1264+
Tests checking Virtual Network Subnet Service Endpoint feature With NetworkIdentifier using ServiceEndpointConfig .
1265+
#>
1266+
function Test-VirtualNetworkSubnetServiceEndpointConfig
1267+
{
1268+
# Setup
1269+
$rgname = Get-ResourceGroupName
1270+
$vnetName = Get-ResourceName
1271+
$subnetName = Get-ResourceName
1272+
$rglocation = Get-ProviderLocation ResourceManagement
1273+
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
1274+
$location = Get-ProviderLocation $resourceTypeParent
1275+
$publicIPAddressName = "PublicIPAddressName";
1276+
$publicIPAddressAllocationMethod = "Static";
1277+
$serviceEndpoint = "Microsoft.Storage"
1278+
1279+
try
1280+
{
1281+
# Create the resource group
1282+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" };
1283+
1284+
# Create the publicip
1285+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIPAddressName -location $location -AllocationMethod $publicIPAddressAllocationMethod
1286+
1287+
# Create the $networkIdentifier
1288+
$networkIdentifier = @{ Id = $publicip.Id };
1289+
$serviceEndpointConfig = @( @{ Service = $ServiceEndpointServiceName; NetworkIdentifier = $NetworkIdentifier })
1290+
1291+
# Create the Virtual Network
1292+
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 -ServiceEndpointConfig $serviceEndpointConfig -NetworkIdentifier $networkIdentifier ;
1293+
New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet;
1294+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname;
1295+
1296+
Assert-NotNull $vnet;
1297+
Assert-NotNull $vnet.Subnets;
1298+
1299+
$subnet = $vnet.Subnets[0];
1300+
Assert-AreEqual $serviceEndpoint $subnet.serviceEndpoints[0].Service;
1301+
Assert-AreEqual $networkIdentifier.Id $subnet.serviceEndpoints[0].networkIdentifier.Id;
1302+
1303+
1304+
Set-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet -AddressPrefix 10.0.1.0/24 -ServiceEndpoint $null;
1305+
$vnet = Set-AzVirtualNetwork -VirtualNetwork $vnet;
1306+
$subnet = $vnet.Subnets[0];
1307+
1308+
Assert-Null $subnet.serviceEndpoints;
1309+
}
1310+
finally
1311+
{
1312+
# Cleanup
1313+
Clean-ResourceGroup $rgname
1314+
}
1315+
}
1316+
12081317
<#
12091318
.SYNOPSIS
12101319
Tests checking Virtual Network Subnet Service Endpoint Policies.

0 commit comments

Comments
 (0)