Skip to content

Add new cmdlets and features to support PrivateIP #9443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.CognitiveServices" Version="6.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.12.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.13.0-preview" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AvailablePrivateEndpointTypeTests(Xunit.Abstractions.ITestOutputHelper ou
{
}

[Fact(Skip = "TODO: record")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
public void TestAvailablePrivateEndpointTypeCRUD()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ function Test-AvailablePrivateEndpointTypeCRUD
# Setup
$rgname = Get-ResourceGroupName;
$rglocation = Get-ProviderLocation ResourceManagement;
$location = Get-ProviderLocation "Microsoft.Network/availablePrivateEndpointTypes" "eastus2euap";
$location = Get-ProviderLocation "Microsoft.Network/availablePrivateEndpointTypes" "westus";

try
{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation;

$vAvailablePrivateEndpointType = Get-AzAvailablePrivateEndpointType -Location eastus2euap;
$vAvailablePrivateEndpointType = Get-AzAvailablePrivateEndpointType -Location $location;
Assert-True { Check-CmdletReturnType "Get-AzAvailablePrivateEndpointType" $vAvailablePrivateEndpointType };
Assert-NotNull $vAvailablePrivateEndpointType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PrivateEndpointTests(Xunit.Abstractions.ITestOutputHelper output)
{
}

[Fact(Skip = "TODO: record")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
public void TestPrivateEndpointCRUD()
Expand Down
99 changes: 66 additions & 33 deletions src/Network/Network.Test/ScenarioTests/PrivateEndpointTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,77 @@ function Test-PrivateEndpointCRUD
{
# Setup
$rgname = Get-ResourceGroupName;
$rglocation = Get-ProviderLocation ResourceManagement;
$rname = Get-ResourceName;
$vnetName = Get-ResourceName;
$location = Get-ProviderLocation "Microsoft.Network/privateEndpoints" "eastus2euap";
# Dependency parameters
$SubnetName = "SubnetName";
$SubnetAddressPrefix = "10.0.1.0/24";
$vnetName = Get-ResourceName;
$ilbFrontName = "LB-Frontend";
$ilbBackendName = "LB-Backend";
$ilbName = Get-ResourceName;
$PrivateLinkServiceConnectionName = "PrivateLinkServiceConnectionName";
$IpConfigurationName = "IpConfigurationName";
$PrivateLinkServiceName = "PrivateLinkServiceName";
$vnetPEName = "VNetPE";

try
{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation;
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location;

# Create Virtual networks
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name "frontendSubnet" -AddressPrefix "10.0.1.0/24";
$backendSubnet = New-AzVirtualNetworkSubnetConfig -Name "backendSubnet" -AddressPrefix "10.0.2.0/24";
$otherSubnet = New-AzVirtualNetworkSubnetConfig -Name "otherSubnet" -AddressPrefix "10.0.3.0/24";
$vnet = New-AzVirtualNetwork -Name "vnet" -ResourceGroupName $rgname -Location $rglocation -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet,$otherSubnet;
$otherSubnet = New-AzVirtualNetworkSubnetConfig -Name "otherSubnet" -AddressPrefix "10.0.3.0/24" -PrivateLinkServiceNetworkPoliciesFlag "Disabled";
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet,$otherSubnet;

# Create LoadBalancer
$frontendIP = New-AzLoadBalancerFrontendIpConfig -Name "LB-Frontend" -PrivateIpAddress 10.0.1.5 -SubnetId $vnet.subnets[0].Id;
$beaddresspool= New-AzLoadBalancerBackendAddressPoolConfig -Name "LB-backend";
$LB = New-AzLoadBalancer -ResourceGroupName $rgname -Name "LB" -Location $rglocation -FrontendIpConfiguration $frontendIP -BackendAddressPool $beaddresspool;

# Create required dependencies for private link service
$IpConfiguration = New-AzPrivateLinkServiceIpConfig -Name $IpConfigurationName -PrivateIpAddress 10.0.3.5 -Subnet $vnet.subnets[2];
$LoadBalancerFrontendIpConfiguration = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $LB;

$frontendIP = New-AzLoadBalancerFrontendIpConfig -Name $ilbFrontName -PrivateIpAddress "10.0.1.5" -SubnetId $vnet.subnets[0].Id;
$beaddresspool= New-AzLoadBalancerBackendAddressPoolConfig -Name $ilbBackendName;
$job = New-AzLoadBalancer -ResourceGroupName $rgname -Name $ilbName -Location $location -FrontendIpConfiguration $frontendIP -BackendAddressPool $beaddresspool -Sku "Standard" -AsJob;
$job | Wait-Job
$ilbcreate = $job | Receive-Job

# Verfify if load balancer is created successfully
Assert-NotNull $ilbcreate;
Assert-AreEqual $ilbName $ilbcreate.Name;
Assert-AreEqual $location $ilbcreate.Location;
Assert-AreEqual "Succeeded" $ilbcreate.ProvisioningState

# Create PrivateLinkService
$vPrivateLinkService = New-AzPrivateLinkService -ResourceGroupName $rgname -ServiceName $PrivateLinkServiceName -Location $location -IpConfiguration $IpConfiguration -LoadBalancerFrontendIpConfiguration $LoadBalancerFrontendIpConfiguration;

# Create required dependencies
$PrivateLinkServiceConnection = New-AzPrivateLinkServiceConnection -Name $PrivateLinkServiceConnectionName -PrivateLinkServiceId $vPrivateLinkService.Id
$IpConfiguration = New-AzPrivateLinkServiceIpConfig -Name $IpConfigurationName -PrivateIpAddress 10.0.3.5 -Subnet $vnet.subnets[2];
$LoadBalancerFrontendIpConfiguration = Get-AzLoadBalancer -Name $ilbName | Get-AzLoadBalancerFrontendIpConfig;

$job = New-AzPrivateLinkService -ResourceGroupName $rgname -Name $PrivateLinkServiceName -Location $location -IpConfiguration $IpConfiguration -LoadBalancerFrontendIpConfiguration $LoadBalancerFrontendIpConfiguration -AsJob;
$job | Wait-Job
$plscreate = $job | Receive-Job
$vPrivateLinkService = Get-AzPrivateLinkService -Name $PrivateLinkServiceName -ResourceGroupName $rgName

# Verfify if private link service is created successfully
Assert-NotNull $vPrivateLinkService;
Assert-AreEqual $PrivateLinkServiceName $vPrivateLinkService.Name;
Assert-NotNull $vPrivateLinkService.IpConfigurations;
Assert-True { $vPrivateLinkService.IpConfigurations.Length -gt 0 };
Assert-AreEqual "Succeeded" $vPrivateLinkService.ProvisioningState

# Create virtual network for private endpoint
$peSubnet = New-AzVirtualNetworkSubnetConfig -Name "peSubnet" -AddressPrefix "11.0.1.0/24" -PrivateEndpointNetworkPoliciesFlag "Disabled"
$vnetPE = New-AzVirtualNetwork -Name $vnetPEName -ResourceGroupName $rgName -Location $location -AddressPrefix "11.0.0.0/16" -Subnet $peSubnet

# Create PrivateEndpoint
$vPrivateEndpoint = New-AzPrivateEndpoint -ResourceGroupName $rgname -Name $rname -Location $location -Subnet $vnet.subnets[2] -PrivateLinkServiceConnection $PrivateLinkServiceConnection;
Assert-NotNull $vPrivateEndpoint;
Assert-True { Check-CmdletReturnType "New-AzPrivateEndpoint" $vPrivateEndpoint };
Assert-NotNull $vPrivateEndpoint.Subnets;
Assert-True { $vPrivateEndpoint.Subnets.Length -gt 0 };
Assert-NotNull $vPrivateEndpoint.PrivateLinkServiceConnections;
Assert-True { $vPrivateEndpoint.PrivateLinkServiceConnections.Length -gt 0 };
Assert-AreEqual $rname $vPrivateEndpoint.Name;
$PrivateLinkServiceConnection = New-AzPrivateLinkServiceConnection -Name $PrivateLinkServiceConnectionName -PrivateLinkServiceId $vPrivateLinkService.Id

# Get PrivateEndpoint
$vPrivateEndpoint = Get-AzPrivateEndpoint -ResourceGroupName $rgname -Name $rname;
$job = New-AzPrivateEndpoint -ResourceGroupName $rgname -Name $rname -Location $location -Subnet $vnetPE.subnets[0] -PrivateLinkServiceConnection $PrivateLinkServiceConnection -AsJob;
$job | Wait-Job
$pecreate = $job | Receive-Job

$vPrivateEndpoint = Get-AzPrivateEndpoint -Name $rname -ResourceGroupName $rgname

# Verification
Assert-NotNull $vPrivateEndpoint;
Assert-True { Check-CmdletReturnType "Get-AzPrivateEndpoint" $vPrivateEndpoint };
Assert-AreEqual $rname $vPrivateEndpoint.Name;
Assert-NotNull $vPrivateEndpoint.Subnet;
Assert-NotNull $vPrivateEndpoint.NetworkInterfaces;
Assert-True { $vPrivateEndpoint.NetworkInterfaces.Length -gt 0 };
Assert-AreEqual "Succeeded" $vPrivateEndpoint.ProvisioningState;

# Get all PrivateEndpoints in resource group
$listPrivateEndpoint = Get-AzPrivateEndpoint -ResourceGroupName $rgname;
Expand All @@ -108,10 +128,23 @@ function Test-PrivateEndpointCRUD
$job = Remove-AzPrivateEndpoint -ResourceGroupName $rgname -Name $rname -PassThru -Force -AsJob;
$job | Wait-Job;
$removePrivateEndpoint = $job | Receive-Job;
Assert-AreEqual $true $removePrivateEndpoint;
Assert-AreEqual true $removePrivateEndpoint;

$list = Get-AzPrivateEndpoint -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count

#Start-Sleep -s 60

# Remove Private Link Service
$job = Remove-AzPrivateLinkService -ResourceGroupName $rgname -Name $PrivateLinkServiceName -PassThru -Force -AsJob;
$job | Wait-Job;
$removePrivateLinkService = $job | Receive-Job;
Assert-AreEqual true $removePrivateLinkService;

$list = Get-AzPrivateLinkService -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count

# Get PrivateEndpoint should fail
Assert-ThrowsContains { Get-AzPrivateEndpoint -ResourceGroupName $rgname -Name $rname } "not found";
#Start-Sleep -s 30
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PrivateLinkServiceTests(Xunit.Abstractions.ITestOutputHelper output)
{
}

[Fact (Skip = "Skipping until PR with PrivateLink updates merged")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
public void TestPrivateLinkServiceCRUD()
Expand Down
57 changes: 34 additions & 23 deletions src/Network/Network.Test/ScenarioTests/PrivateLinkServiceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,55 @@ function Test-PrivateLinkServiceCRUD
{
# Setup
$rgname = Get-ResourceGroupName;
$rglocation = "eastus2euap";
$rname = Get-ResourceName;
$location = Get-ProviderLocation "Microsoft.Network/privateLinkServices" "eastus2euap";
# Dependency parameters
$IpConfigurationName = "IpConfigurationName";
$vnetName = Get-ResourceName;
$ilbFrontName = "LB-Frontend";
$ilbBackendName = "LB-Backend";
$ilbName = Get-ResourceName;

try
{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation;
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location;

# Create Virtual networks
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name "frontendSubnet" -AddressPrefix "10.0.1.0/24";
$backendSubnet = New-AzVirtualNetworkSubnetConfig -Name "backendSubnet" -AddressPrefix "10.0.2.0/24";
$otherSubnet = New-AzVirtualNetworkSubnetConfig -Name "otherSubnet" -AddressPrefix "10.0.3.0/24";
$vnet = New-AzVirtualNetwork -Name "vnet" -ResourceGroupName $rgname -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet,$otherSubnet;
$otherSubnet = New-AzVirtualNetworkSubnetConfig -Name "otherSubnet" -AddressPrefix "10.0.3.0/24" -PrivateLinkServiceNetworkPoliciesFlag "Disabled";
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet,$otherSubnet;

# Create LoadBalancer
$frontendIP = New-AzLoadBalancerFrontendIpConfig -Name "LB-Frontend" -PrivateIpAddress 10.0.1.5 -SubnetId $vnet.subnets[0].Id;
$beaddresspool= New-AzLoadBalancerBackendAddressPoolConfig -Name "LB-backend";
$LB = New-AzLoadBalancer -ResourceGroupName $rgname -Name "LB" -Location $location -FrontendIpConfiguration $frontendIP -BackendAddressPool $beaddresspool -Sku Standard;

$frontendIP = New-AzLoadBalancerFrontendIpConfig -Name $ilbFrontName -PrivateIpAddress "10.0.1.5" -SubnetId $vnet.subnets[0].Id;
$beaddresspool= New-AzLoadBalancerBackendAddressPoolConfig -Name $ilbBackendName;
$job = New-AzLoadBalancer -ResourceGroupName $rgname -Name $ilbName -Location $location -FrontendIpConfiguration $frontendIP -BackendAddressPool $beaddresspool -Sku "Standard" -AsJob;
$job | Wait-Job
$ilbcreate = $job | Receive-Job

# Verfify if load balancer is created successfully
Assert-NotNull $ilbcreate;
Assert-AreEqual $ilbName $ilbcreate.Name;
Assert-AreEqual $location $ilbcreate.Location;
Assert-AreEqual "Succeeded" $ilbcreate.ProvisioningState

# Create required dependencies
$IpConfiguration = New-AzPrivateLinkServiceIpConfig -Name $IpConfigurationName -PrivateIpAddress 10.0.3.5 -Subnet $vnet.subnets[2];
$LoadBalancerFrontendIpConfiguration = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $LB;
$LoadBalancerFrontendIpConfiguration = Get-AzLoadBalancer -Name $ilbName | Get-AzLoadBalancerFrontendIpConfig

# Create PrivateLinkService
$vPrivateLinkService = New-AzPrivateLinkService -ResourceGroupName $rgName -ServiceName $rname -Location $location -IpConfiguration $IpConfiguration -LoadBalancerFrontendIpConfiguration $LoadBalancerFrontendIpConfiguration;
$job = New-AzPrivateLinkService -ResourceGroupName $rgName -Name $rname -Location $location -IpConfiguration $IpConfiguration -LoadBalancerFrontendIpConfiguration $LoadBalancerFrontendIpConfiguration -AsJob;
$job | Wait-Job
$plscreate = $job | Receive-Job

$vPrivateLinkService = Get-AzPrivateLinkService -Name $rname -ResourceGroupName $rgName

# Verification
Assert-NotNull $vPrivateLinkService;
Assert-True { Check-CmdletReturnType "New-AzPrivateLinkService" $vPrivateLinkService };
Assert-AreEqual $rname $vPrivateLinkService.Name;
Assert-NotNull $vPrivateLinkService.IpConfigurations;
Assert-True { $vPrivateLinkService.IpConfigurations.Length -gt 0 };
Assert-AreEqual $rname $vPrivateLinkService.Name;

# Get PrivateLinkService
$vPrivateLinkService = Get-AzPrivateLinkService -ResourceGroupName $rgname -Name $rname;
Assert-NotNull $vPrivateLinkService;
Assert-True { Check-CmdletReturnType "Get-AzPrivateLinkService" $vPrivateLinkService };
Assert-AreEqual $rname $vPrivateLinkService.Name;
Assert-AreEqual "Succeeded" $vPrivateLinkService.ProvisioningState

# Get all PrivateLinkServices in resource group
$listPrivateLinkService = Get-AzPrivateLinkService -ResourceGroupName $rgname;
Expand All @@ -92,18 +103,18 @@ function Test-PrivateLinkServiceCRUD
Assert-NotNull ($listPrivateLinkService | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });

# Remove PrivateLinkService
$job = Remove-AzPrivateLinkService -ResourceGroupName $rgname -ServiceName $rname -PassThru -Force -AsJob;
$job = Remove-AzPrivateLinkService -ResourceGroupName $rgname -Name $rname -PassThru -Force -AsJob;
$job | Wait-Job;
$removePrivateLinkService = $job | Receive-Job;
Assert-AreEqual $true $removePrivateLinkService;
Assert-AreEqual true $removePrivateLinkService;

# Get PrivateLinkService should fail
Assert-ThrowsLike { Get-AzPrivateLinkService -ResourceGroupName $rgname -Name $rname } "*not*found*";
$list = Get-AzPrivateLinkService -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Rest.Azure;
using CNM = Microsoft.Azure.Commands.Network.Models;

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AvailablePrivateEndpointType"), OutputType(typeof(PSAvailablePrivateEndpointType))]
public class GetAzureAvailablePrivateEndpointTypeCommand : NetworkBaseCmdlet
public class GetAzureAvailablePrivateEndpointTypeCommand : PrivateEndpointBaseCmdlet
{
[Parameter(
Mandatory = true,
Expand All @@ -34,11 +36,29 @@ public class GetAzureAvailablePrivateEndpointTypeCommand : NetworkBaseCmdlet
[ValidateNotNullOrEmpty]
public string Location { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
[SupportsWildcards]
public string ResourceGroupName { get; set; }

public override void Execute()
{
base.Execute();

var availablePrivateEndpointList = this.NetworkClient.NetworkManagementClient.AvailablePrivateEndpointTypes.List(Location);
IPage<AvailablePrivateEndpointType> availablePrivateEndpointList = null;
if (!string.IsNullOrEmpty(ResourceGroupName))
{
availablePrivateEndpointList = this.NetworkClient.NetworkManagementClient.AvailablePrivateEndpointTypes.ListByResourceGroup(this.Location, this.ResourceGroupName);
}
else
{
availablePrivateEndpointList = this.NetworkClient.NetworkManagementClient.AvailablePrivateEndpointTypes.List(Location);
}

List<PSAvailablePrivateEndpointType> psPrivateEndpoints = new List<PSAvailablePrivateEndpointType>();
foreach (var availablePrivateEndpoint in availablePrivateEndpointList)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,15 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'Remove-AzPrivateEndpoint', 'New-AzPrivateLinkServiceConnection',
'New-AzPrivateLinkService', 'Get-AzPrivateLinkService',
'Remove-AzPrivateLinkService', 'New-AzPrivateLinkServiceIpConfig',
'Set-AzPrivateEndpoint',
'Set-AzPrivateLinkService',
'Set-AzPrivateEndpointConnection',
'Get-AzPrivateEndpointConnection',
'Remove-AzPrivateEndpointConnection',
'Get-AzAutoApprovedPrivateLinkService',
'Test-AzPrivateLinkServiceVisibility',
'Approve-AzPrivateEndpointConnection',
'Deny-AzPrivateEndpointConnection',
'Get-AzAvailablePrivateEndpointType'

# Variables to export from this module
Expand Down
Loading