@@ -1205,6 +1205,115 @@ function Test-VirtualNetworkSubnetServiceEndpoint
1205
1205
}
1206
1206
}
1207
1207
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
+
1208
1317
<#
1209
1318
. SYNOPSIS
1210
1319
Tests checking Virtual Network Subnet Service Endpoint Policies.
0 commit comments