@@ -32,57 +32,77 @@ function Test-PrivateEndpointCRUD
32
32
{
33
33
# Setup
34
34
$rgname = Get-ResourceGroupName ;
35
- $rglocation = Get-ProviderLocation ResourceManagement;
36
35
$rname = Get-ResourceName ;
37
- $vnetName = Get-ResourceName ;
38
36
$location = Get-ProviderLocation " Microsoft.Network/privateEndpoints" " eastus2euap" ;
39
37
# Dependency parameters
40
- $SubnetName = " SubnetName" ;
41
- $SubnetAddressPrefix = " 10.0.1.0/24" ;
38
+ $vnetName = Get-ResourceName ;
39
+ $ilbFrontName = " LB-Frontend" ;
40
+ $ilbBackendName = " LB-Backend" ;
41
+ $ilbName = Get-ResourceName ;
42
42
$PrivateLinkServiceConnectionName = " PrivateLinkServiceConnectionName" ;
43
43
$IpConfigurationName = " IpConfigurationName" ;
44
44
$PrivateLinkServiceName = " PrivateLinkServiceName" ;
45
+ $vnetPEName = " VNetPE" ;
45
46
46
47
try
47
48
{
48
- $resourceGroup = New-AzResourceGroup - Name $rgname - Location $rglocation ;
49
+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $location ;
49
50
50
51
# Create Virtual networks
51
52
$frontendSubnet = New-AzVirtualNetworkSubnetConfig - Name " frontendSubnet" - AddressPrefix " 10.0.1.0/24" ;
52
53
$backendSubnet = New-AzVirtualNetworkSubnetConfig - Name " backendSubnet" - AddressPrefix " 10.0.2.0/24" ;
53
- $otherSubnet = New-AzVirtualNetworkSubnetConfig - Name " otherSubnet" - AddressPrefix " 10.0.3.0/24" ;
54
- $vnet = New-AzVirtualNetwork - Name " vnet " - ResourceGroupName $rgname - Location $rglocation - AddressPrefix " 10.0.0.0/16" - Subnet $frontendSubnet , $backendSubnet , $otherSubnet ;
54
+ $otherSubnet = New-AzVirtualNetworkSubnetConfig - Name " otherSubnet" - AddressPrefix " 10.0.3.0/24" - PrivateLinkServiceNetworkPoliciesFlag " Disabled " ;
55
+ $vnet = New-AzVirtualNetwork - Name $vnetName - ResourceGroupName $rgname - Location $location - AddressPrefix " 10.0.0.0/16" - Subnet $frontendSubnet , $backendSubnet , $otherSubnet ;
55
56
56
57
# Create LoadBalancer
57
- $frontendIP = New-AzLoadBalancerFrontendIpConfig - Name " LB-Frontend" - PrivateIpAddress 10.0 .1.5 - SubnetId $vnet.subnets [0 ].Id;
58
- $beaddresspool = New-AzLoadBalancerBackendAddressPoolConfig - Name " LB-backend" ;
59
- $LB = New-AzLoadBalancer - ResourceGroupName $rgname - Name " LB" - Location $rglocation - FrontendIpConfiguration $frontendIP - BackendAddressPool $beaddresspool ;
60
-
61
- # Create required dependencies for private link service
62
- $IpConfiguration = New-AzPrivateLinkServiceIpConfig - Name $IpConfigurationName - PrivateIpAddress 10.0 .3.5 - Subnet $vnet.subnets [2 ];
63
- $LoadBalancerFrontendIpConfiguration = Get-AzLoadBalancerFrontendIpConfig - LoadBalancer $LB ;
64
-
58
+ $frontendIP = New-AzLoadBalancerFrontendIpConfig - Name $ilbFrontName - PrivateIpAddress " 10.0.1.5" - SubnetId $vnet.subnets [0 ].Id;
59
+ $beaddresspool = New-AzLoadBalancerBackendAddressPoolConfig - Name $ilbBackendName ;
60
+ $job = New-AzLoadBalancer - ResourceGroupName $rgname - Name $ilbName - Location $location - FrontendIpConfiguration $frontendIP - BackendAddressPool $beaddresspool - Sku " Standard" - AsJob;
61
+ $job | Wait-Job
62
+ $ilbcreate = $job | Receive-Job
63
+
64
+ # Verfify if load balancer is created successfully
65
+ Assert-NotNull $ilbcreate ;
66
+ Assert-AreEqual $ilbName $ilbcreate.Name ;
67
+ Assert-AreEqual $location $ilbcreate.Location ;
68
+ Assert-AreEqual " Succeeded" $ilbcreate.ProvisioningState
69
+
65
70
# Create PrivateLinkService
66
- $vPrivateLinkService = New-AzPrivateLinkService - ResourceGroupName $rgname - ServiceName $PrivateLinkServiceName - Location $location - IpConfiguration $IpConfiguration - LoadBalancerFrontendIpConfiguration $LoadBalancerFrontendIpConfiguration ;
67
-
68
- # Create required dependencies
69
- $PrivateLinkServiceConnection = New-AzPrivateLinkServiceConnection - Name $PrivateLinkServiceConnectionName - PrivateLinkServiceId $vPrivateLinkService.Id
71
+ $IpConfiguration = New-AzPrivateLinkServiceIpConfig - Name $IpConfigurationName - PrivateIpAddress 10.0 .3.5 - Subnet $vnet.subnets [2 ];
72
+ $LoadBalancerFrontendIpConfiguration = Get-AzLoadBalancer - Name $ilbName | Get-AzLoadBalancerFrontendIpConfig ;
73
+
74
+ $job = New-AzPrivateLinkService - ResourceGroupName $rgname - Name $PrivateLinkServiceName - Location $location - IpConfiguration $IpConfiguration - LoadBalancerFrontendIpConfiguration $LoadBalancerFrontendIpConfiguration - AsJob;
75
+ $job | Wait-Job
76
+ $plscreate = $job | Receive-Job
77
+ $vPrivateLinkService = Get-AzPrivateLinkService - Name $PrivateLinkServiceName - ResourceGroupName $rgName
78
+
79
+ # Verfify if private link service is created successfully
80
+ Assert-NotNull $vPrivateLinkService ;
81
+ Assert-AreEqual $PrivateLinkServiceName $vPrivateLinkService.Name ;
82
+ Assert-NotNull $vPrivateLinkService.IpConfigurations ;
83
+ Assert-True { $vPrivateLinkService.IpConfigurations.Length -gt 0 };
84
+ Assert-AreEqual " Succeeded" $vPrivateLinkService.ProvisioningState
85
+
86
+ # Create virtual network for private endpoint
87
+ $peSubnet = New-AzVirtualNetworkSubnetConfig - Name " peSubnet" - AddressPrefix " 11.0.1.0/24" - PrivateEndpointNetworkPoliciesFlag " Disabled"
88
+ $vnetPE = New-AzVirtualNetwork - Name $vnetPEName - ResourceGroupName $rgName - Location $location - AddressPrefix " 11.0.0.0/16" - Subnet $peSubnet
70
89
71
90
# Create PrivateEndpoint
72
- $vPrivateEndpoint = New-AzPrivateEndpoint - ResourceGroupName $rgname - Name $rname - Location $location - Subnet $vnet.subnets [2 ] - PrivateLinkServiceConnection $PrivateLinkServiceConnection ;
73
- Assert-NotNull $vPrivateEndpoint ;
74
- Assert-True { Check- CmdletReturnType " New-AzPrivateEndpoint" $vPrivateEndpoint };
75
- Assert-NotNull $vPrivateEndpoint.Subnets ;
76
- Assert-True { $vPrivateEndpoint.Subnets.Length -gt 0 };
77
- Assert-NotNull $vPrivateEndpoint.PrivateLinkServiceConnections ;
78
- Assert-True { $vPrivateEndpoint.PrivateLinkServiceConnections.Length -gt 0 };
79
- Assert-AreEqual $rname $vPrivateEndpoint.Name ;
91
+ $PrivateLinkServiceConnection = New-AzPrivateLinkServiceConnection - Name $PrivateLinkServiceConnectionName - PrivateLinkServiceId $vPrivateLinkService.Id
80
92
81
- # Get PrivateEndpoint
82
- $vPrivateEndpoint = Get-AzPrivateEndpoint - ResourceGroupName $rgname - Name $rname ;
93
+ $job = New-AzPrivateEndpoint - ResourceGroupName $rgname - Name $rname - Location $location - Subnet $vnetPE.subnets [0 ] - PrivateLinkServiceConnection $PrivateLinkServiceConnection - AsJob;
94
+ $job | Wait-Job
95
+ $pecreate = $job | Receive-Job
96
+
97
+ $vPrivateEndpoint = Get-AzPrivateEndpoint - Name $rname - ResourceGroupName $rgname
98
+
99
+ # Verification
83
100
Assert-NotNull $vPrivateEndpoint ;
84
- Assert-True { Check- CmdletReturnType " Get-AzPrivateEndpoint" $vPrivateEndpoint };
85
101
Assert-AreEqual $rname $vPrivateEndpoint.Name ;
102
+ Assert-NotNull $vPrivateEndpoint.Subnet ;
103
+ Assert-NotNull $vPrivateEndpoint.NetworkInterfaces ;
104
+ Assert-True { $vPrivateEndpoint.NetworkInterfaces.Length -gt 0 };
105
+ Assert-AreEqual " Succeeded" $vPrivateEndpoint.ProvisioningState ;
86
106
87
107
# Get all PrivateEndpoints in resource group
88
108
$listPrivateEndpoint = Get-AzPrivateEndpoint - ResourceGroupName $rgname ;
@@ -108,10 +128,23 @@ function Test-PrivateEndpointCRUD
108
128
$job = Remove-AzPrivateEndpoint - ResourceGroupName $rgname - Name $rname - PassThru - Force - AsJob;
109
129
$job | Wait-Job ;
110
130
$removePrivateEndpoint = $job | Receive-Job ;
111
- Assert-AreEqual $true $removePrivateEndpoint ;
131
+ Assert-AreEqual true $removePrivateEndpoint ;
132
+
133
+ $list = Get-AzPrivateEndpoint - ResourceGroupName $rgname
134
+ Assert-AreEqual 0 @ ($list ).Count
135
+
136
+ # Start-Sleep -s 60
137
+
138
+ # Remove Private Link Service
139
+ $job = Remove-AzPrivateLinkService - ResourceGroupName $rgname - Name $PrivateLinkServiceName - PassThru - Force - AsJob;
140
+ $job | Wait-Job ;
141
+ $removePrivateLinkService = $job | Receive-Job ;
142
+ Assert-AreEqual true $removePrivateLinkService ;
143
+
144
+ $list = Get-AzPrivateLinkService - ResourceGroupName $rgname
145
+ Assert-AreEqual 0 @ ($list ).Count
112
146
113
- # Get PrivateEndpoint should fail
114
- Assert-ThrowsContains { Get-AzPrivateEndpoint - ResourceGroupName $rgname - Name $rname } " not found" ;
147
+ # Start-Sleep -s 30
115
148
}
116
149
finally
117
150
{
0 commit comments