Skip to content

Commit 5edae7d

Browse files
wdehrichWill Ehrich
andauthored
Add edge zone parameter to private endpoint cmdlet (Azure#15287)
* Add edge zone parameter to private endpoint cmdlet * Scenario test shell * Update change log * Boilerplate code * Refactor test * Another test refactor * It is working with edge zone * Add test session record * Fix whitespace Co-authored-by: Will Ehrich <[email protected]>
1 parent 802364c commit 5edae7d

File tree

8 files changed

+3336
-27
lines changed

8 files changed

+3336
-27
lines changed

src/Network/Network.Test/ScenarioTests/PrivateEndpointTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public void TestPrivateEndpointCRUD()
3333
TestRunner.RunTestScript("Test-PrivateEndpointCRUD");
3434
}
3535

36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
39+
public void TestPrivateEndpointInEdgeZone()
40+
{
41+
TestRunner.RunTestScript("Test-PrivateEndpointInEdgeZone");
42+
}
43+
3644
[Fact]
3745
[Trait(Category.AcceptanceType, Category.CheckIn)]
3846
[Trait(Category.Owner, NrpTeamAlias.azdevxps)]

src/Network/Network.Test/ScenarioTests/PrivateEndpointTests.ps1

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,83 @@ function Test-PrivateDnsZoneGroupCRUD
265265
# Cleanup
266266
Clean-ResourceGroup $rgname;
267267
}
268+
}
269+
270+
<#
271+
.SYNOPSIS
272+
Test creating a private endpoint in an edge zone. Subscriptions need to be explicitly whitelisted for access to edge zones.
273+
#>
274+
function Test-PrivateEndpointInEdgeZone
275+
{
276+
# Setup
277+
$rgname = Get-ResourceGroupName
278+
$rname = Get-ResourceName
279+
$location = "westus"
280+
# Dependency parameters
281+
$vnetName = Get-ResourceName
282+
$ilbFrontName = "LB-Frontend"
283+
$ilbBackendName = "LB-Backend"
284+
$ilbName = Get-ResourceName
285+
$PrivateLinkServiceConnectionName = "PrivateLinkServiceConnectionName"
286+
$IpConfigurationName = "IpConfigurationName"
287+
$PrivateLinkServiceName = "PrivateLinkServiceName"
288+
$vnetPEName = "VNetPE"
289+
$edgeZone = "microsoftlosangeles1"
290+
291+
try
292+
{
293+
New-AzResourceGroup -Name $rgname -Location $location
294+
295+
# Create Virtual networks
296+
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name "frontendSubnet" -AddressPrefix "10.0.1.0/24"
297+
$backendSubnet = New-AzVirtualNetworkSubnetConfig -Name "backendSubnet" -AddressPrefix "10.0.2.0/24"
298+
$otherSubnet = New-AzVirtualNetworkSubnetConfig -Name "otherSubnet" -AddressPrefix "10.0.3.0/24" -PrivateLinkServiceNetworkPoliciesFlag "Disabled"
299+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet,$otherSubnet -EdgeZone $edgeZone
300+
301+
# Create LoadBalancer
302+
$frontendIP = New-AzLoadBalancerFrontendIpConfig -Name $ilbFrontName -PrivateIpAddress "10.0.1.5" -SubnetId $vnet.subnets[0].Id
303+
$beaddresspool= New-AzLoadBalancerBackendAddressPoolConfig -Name $ilbBackendName
304+
$ilbcreate = New-AzLoadBalancer -ResourceGroupName $rgname -Name $ilbName -Location $location -FrontendIpConfiguration $frontendIP -BackendAddressPool $beaddresspool -Sku "Standard" -EdgeZone $edgeZone
305+
306+
# Verfify if load balancer is created successfully
307+
Assert-NotNull $ilbcreate
308+
Assert-AreEqual $ilbName $ilbcreate.Name
309+
Assert-AreEqual $location $ilbcreate.Location
310+
Assert-AreEqual "Succeeded" $ilbcreate.ProvisioningState
311+
312+
# Create PrivateLinkService
313+
$IpConfiguration = New-AzPrivateLinkServiceIpConfig -Name $IpConfigurationName -PrivateIpAddress 10.0.3.5 -Subnet $vnet.subnets[2]
314+
$LoadBalancerFrontendIpConfiguration = Get-AzLoadBalancer -Name $ilbName | Get-AzLoadBalancerFrontendIpConfig
315+
316+
$vPrivateLinkService = New-AzPrivateLinkService -ResourceGroupName $rgname -Name $PrivateLinkServiceName -Location $location -IpConfiguration $IpConfiguration -LoadBalancerFrontendIpConfiguration $LoadBalancerFrontendIpConfiguration -EdgeZone $edgeZone
317+
318+
# Verfify if private link service is created successfully
319+
Assert-NotNull $vPrivateLinkService
320+
Assert-AreEqual $PrivateLinkServiceName $vPrivateLinkService.Name
321+
Assert-NotNull $vPrivateLinkService.IpConfigurations;
322+
Assert-True { $vPrivateLinkService.IpConfigurations.Length -gt 0 }
323+
Assert-AreEqual "Succeeded" $vPrivateLinkService.ProvisioningState
324+
325+
# Create virtual network for private endpoint
326+
$peSubnet = New-AzVirtualNetworkSubnetConfig -Name "peSubnet" -AddressPrefix "11.0.1.0/24" -PrivateEndpointNetworkPoliciesFlag "Disabled"
327+
$vnetPE = New-AzVirtualNetwork -Name $vnetPEName -ResourceGroupName $rgName -Location $location -AddressPrefix "11.0.0.0/16" -Subnet $peSubnet -EdgeZone $edgeZone
328+
329+
# Create PrivateEndpoint
330+
$PrivateLinkServiceConnection = New-AzPrivateLinkServiceConnection -Name $PrivateLinkServiceConnectionName -PrivateLinkServiceId $vPrivateLinkService.Id
331+
New-AzPrivateEndpoint -ResourceGroupName $rgname -Name $rname -Location $location -Subnet $vnetPE.subnets[0] -PrivateLinkServiceConnection $PrivateLinkServiceConnection -EdgeZone $edgeZone
332+
333+
$vPrivateEndpoint = Get-AzPrivateEndpoint -Name $rname -ResourceGroupName $rgname
334+
335+
Assert-AreEqual $vPrivateEndpoint.ExtendedLocation.Name $edgeZone
336+
Assert-AreEqual $vPrivateEndpoint.ExtendedLocation.Type "EdgeZone"
337+
}
338+
catch [Microsoft.Azure.Commands.Network.Common.NetworkCloudException]
339+
{
340+
Assert-NotNull { $_.Exception.Message -match 'Resource type .* does not support edge zone .* in location .* The supported edge zones are .*' }
341+
}
342+
finally
343+
{
344+
# Cleanup
345+
Clean-ResourceGroup $rgname
346+
}
268347
}

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.PrivateEndpointTests/TestPrivateEndpointInEdgeZone.json

Lines changed: 3202 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- `New-AzPublicIpPrefix`
2424
- `New-AzLoadBalancer`
2525
- `New-AzPrivateLinkService`
26+
- `New-AzPrivateEndpoint`
2627
* Added support for viewing extended location of virtual network in the console
2728
- `New-AzVirtualNetwork`
2829
- `Get-AzVirtualNetwork`

src/Network/Network/Models/PSPrivateEndpoint.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
// <auto-generated>
2-
// Copyright (c) Microsoft and contributors. All rights reserved.
3-
//
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
66
// You may obtain a copy of the License at
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
98
// Unless required by applicable law or agreed to in writing, software
109
// distributed under the License is distributed on an "AS IS" BASIS,
1110
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
//
1311
// See the License for the specific language governing permissions and
1412
// limitations under the License.
15-
//
16-
//
17-
// Warning: This code was generated by a tool.
18-
//
19-
// Changes to this file may cause incorrect behavior and will be lost if the
20-
// code is regenerated.
21-
//
22-
// For documentation on code generator please visit
23-
// https://aka.ms/nrp-code-generation
24-
// Please contact [email protected] if you need to make changes to this file.
25-
// </auto-generated>
13+
// ----------------------------------------------------------------------------------
2614

2715
using Microsoft.Azure.Management.Network.Models;
2816
using Microsoft.WindowsAzure.Commands.Common.Attributes;
@@ -41,6 +29,7 @@ public partial class PSPrivateEndpoint : PSTopLevelResource
4129
public List<PSPrivateLinkServiceConnection> PrivateLinkServiceConnections { get; set; }
4230
public List<PSPrivateLinkServiceConnection> ManualPrivateLinkServiceConnections { get; set; }
4331
public List<PSPrivateEndpointCustomDnsConfig> CustomDnsConfigs { get; set; }
32+
public PSExtendedLocation ExtendedLocation { get; set; }
4433

4534
[JsonIgnore]
4635
public string SubnetText
@@ -72,6 +61,11 @@ public string CustomDnsConfigsText
7261
get { return JsonConvert.SerializeObject(CustomDnsConfigs, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
7362
}
7463

64+
[JsonIgnore]
65+
public string ExtendedLocationText
66+
{
67+
get { return JsonConvert.SerializeObject(ExtendedLocation, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
68+
}
7569

7670
public bool ShouldSerializeNetworkInterfaces()
7771
{

src/Network/Network/Network.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5129,6 +5129,10 @@
51295129
<Label>CustomDnsConfigs</Label>
51305130
<PropertyName>CustomDnsConfigsText</PropertyName>
51315131
</ListItem>
5132+
<ListItem>
5133+
<Label>ExtendedLocation</Label>
5134+
<PropertyName>ExtendedLocationText</PropertyName>
5135+
</ListItem>
51325136
</ListItems>
51335137
</ListEntry>
51345138
</ListEntries>

src/Network/Network/PrivateEndpoint/NewAzurePrivateEndpointCommand.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public class NewAzurePrivateEndpoint : PrivateEndpointBaseCmdlet
6969
HelpMessage = "Using manual request.")]
7070
public SwitchParameter ByManualRequest { get; set; }
7171

72+
[Parameter(
73+
Mandatory = false,
74+
ValueFromPipelineByPropertyName = true,
75+
HelpMessage = "The edge zone of the private endpoint")]
76+
public string EdgeZone { get; set; }
77+
7278
[Parameter(
7379
Mandatory = false,
7480
ValueFromPipelineByPropertyName = true,
@@ -103,7 +109,12 @@ private PSPrivateEndpoint CreatePSPrivateEndpoint()
103109
{
104110
psPrivateEndpoint.PrivateLinkServiceConnections = this.PrivateLinkServiceConnection.ToList();
105111
}
106-
112+
113+
if (!string.IsNullOrEmpty(this.EdgeZone))
114+
{
115+
psPrivateEndpoint.ExtendedLocation = new PSExtendedLocation(this.EdgeZone);
116+
}
117+
107118
var peModel = NetworkResourceManagerProfile.Mapper.Map<MNM.PrivateEndpoint>(psPrivateEndpoint);
108119
peModel.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);
109120

src/Network/Network/help/New-AzPrivateEndpoint.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ Creates a private endpoint.
1212

1313
## SYNTAX
1414

15-
### All
16-
1715
```
1816
New-AzPrivateEndpoint -Name <String> -ResourceGroupName <String> -Location <String> -Subnet <PSSubnet>
19-
-PrivateLinkServiceConnection <PSPrivateLinkServiceConnection[]> [-ByManualRequest] [-Tag <Hashtable>]
20-
[-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
17+
-PrivateLinkServiceConnection <PSPrivateLinkServiceConnection[]> [-ByManualRequest] [-EdgeZone <String>]
18+
[-Tag <Hashtable>] [-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
19+
[<CommonParameters>]
2120
```
2221

2322
## DESCRIPTION
@@ -88,6 +87,21 @@ Accept pipeline input: False
8887
Accept wildcard characters: False
8988
```
9089
90+
### -EdgeZone
91+
The edge zone of the private endpoint
92+
93+
```yaml
94+
Type: System.String
95+
Parameter Sets: (All)
96+
Aliases:
97+
98+
Required: False
99+
Position: Named
100+
Default value: None
101+
Accept pipeline input: True (ByPropertyName)
102+
Accept wildcard characters: False
103+
```
104+
91105
### -Force
92106
93107
Do not ask for confirmation to overwrite a resource.
@@ -236,11 +250,7 @@ Accept wildcard characters: False
236250
```
237251
238252
### CommonParameters
239-
240-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
241-
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
242-
-WarningAction, and -WarningVariable. For more information, see
243-
[about_CommonParameters](/powershell/module/microsoft.powershell.core/about/about_commonparameters).
253+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
244254
245255
## INPUTS
246256

0 commit comments

Comments
 (0)