@@ -2946,3 +2946,174 @@ function Test-ApplicationGatewayWithPrivateLinkConfiguration
2946
2946
Clean - ResourceGroup $rgname
2947
2947
}
2948
2948
}
2949
+
2950
+ function Test-ApplicationGatewayPrivateEndpointWorkFlows
2951
+ {
2952
+ param
2953
+ (
2954
+ $basedir = " ./"
2955
+ )
2956
+
2957
+ # Setup
2958
+ $location = Get-ProviderLocation " Microsoft.Network/applicationGateways" " westus2"
2959
+
2960
+ $rgname = Get-ResourceGroupName
2961
+ $appgwName = Get-ResourceName
2962
+ $vnetName = Get-ResourceName
2963
+ $gwSubnetName = Get-ResourceName
2964
+ $plsSubnetName = Get-ResourceName
2965
+ $publicIpName = Get-ResourceName
2966
+ $gipconfigname = Get-ResourceName
2967
+
2968
+ $frontendPort01Name = Get-ResourceName
2969
+ $fipconfigName = Get-ResourceName
2970
+ $listener01Name = Get-ResourceName
2971
+
2972
+ $poolName = Get-ResourceName
2973
+ $trustedRootCertName = Get-ResourceName
2974
+ $poolSetting01Name = Get-ResourceName
2975
+
2976
+ $rule01Name = Get-ResourceName
2977
+
2978
+ $probeHttpName = Get-ResourceName
2979
+
2980
+ $privateLinkIpConfigName = Get-ResourceName
2981
+ $privateLinkConfigName = Get-ResourceName
2982
+
2983
+ $peRgName = Get-ResourceGroupName
2984
+ $peVnetName = Get-ResourceName
2985
+ $peSubnetName = Get-ResourceName
2986
+ $peName = Get-ResourceName
2987
+ $peConnName = Get-ResourceName
2988
+
2989
+ try
2990
+ {
2991
+ # Create the appgw resource group
2992
+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $location - Tags @ { testtag = " APPGw tag" }
2993
+ # Create the Virtual Network
2994
+ $gwSubnet = New-AzVirtualNetworkSubnetConfig - Name $gwSubnetName - AddressPrefix 10.0 .0.0 / 24 - PrivateLinkServiceNetworkPoliciesFlag " Disabled"
2995
+ $plsSubnet = New-AzVirtualNetworkSubnetConfig - Name $plsSubnetName - AddressPrefix 10.0 .1.0 / 24 - PrivateLinkServiceNetworkPoliciesFlag " Disabled"
2996
+ $vnet = New-AzVirtualNetwork - Name $vnetName - ResourceGroupName $rgname - Location $location - AddressPrefix 10.0 .0.0 / 16 - Subnet $gwSubnet , $plsSubnet
2997
+ $vnet = Get-AzVirtualNetwork - Name $vnetName - ResourceGroupName $rgname
2998
+ $gwSubnet = Get-AzVirtualNetworkSubnetConfig - Name $gwSubnetName - VirtualNetwork $vnet
2999
+ $plsSubnet = Get-AzVirtualNetworkSubnetConfig - Name $plsSubnetName - VirtualNetwork $vnet
3000
+
3001
+ # Create public ip
3002
+ $publicip = New-AzPublicIpAddress - ResourceGroupName $rgname - name $publicIpName - location $location - AllocationMethod Static - sku Standard
3003
+
3004
+ # Create ip configuration
3005
+ $gipconfig = New-AzApplicationGatewayIPConfiguration - Name $gipconfigname - Subnet $gwSubnet
3006
+
3007
+ # private link configuration
3008
+ $privateLinkIpConfiguration = New-AzApplicationGatewayPrivateLinkIpConfiguration - Name $privateLinkIpConfigName - Subnet $plsSubnet - Primary
3009
+ $privateLinkConfiguration = New-AzApplicationGatewayPrivateLinkConfiguration - Name $privateLinkConfigName - IpConfiguration $privateLinkIpConfiguration
3010
+
3011
+ $fipconfig = New-AzApplicationGatewayFrontendIPConfig - Name $fipconfigName - PublicIPAddress $publicip - PrivateLinkConfiguration $privateLinkConfiguration
3012
+ $fp01 = New-AzApplicationGatewayFrontendPort - Name $frontendPort01Name - Port 80
3013
+ $listener01 = New-AzApplicationGatewayHttpListener - Name $listener01Name - Protocol Http - FrontendIPConfiguration $fipconfig - FrontendPort $fp01
3014
+
3015
+ # backend part
3016
+ # trusted root cert part
3017
+ $certFilePath = $basedir + " /ScenarioTests/Data/ApplicationGatewayAuthCert.cer"
3018
+ $trustedRoot01 = New-AzApplicationGatewayTrustedRootCertificate - Name $trustedRootCertName - CertificateFile $certFilePath
3019
+ $pool = New-AzApplicationGatewayBackendAddressPool - Name $poolName - BackendIPAddresses www.microsoft.com , www.bing.com
3020
+ $probeHttp = New-AzApplicationGatewayProbeConfig - Name $probeHttpName - Protocol Https - HostName " probe.com" - Path " /path/path.htm" - Interval 89 - Timeout 88 - UnhealthyThreshold 8 - port 1234
3021
+ $poolSetting01 = New-AzApplicationGatewayBackendHttpSetting - Name $poolSetting01Name - Port 443 - Protocol Https - Probe $probeHttp - CookieBasedAffinity Enabled - PickHostNameFromBackendAddress - TrustedRootCertificate $trustedRoot01
3022
+
3023
+ # rule
3024
+ $rule01 = New-AzApplicationGatewayRequestRoutingRule - Name $rule01Name - RuleType basic - BackendHttpSettings $poolSetting01 - HttpListener $listener01 - BackendAddressPool $pool
3025
+
3026
+ # sku
3027
+ $sku = New-AzApplicationGatewaySku - Name Standard_v2 - Tier Standard_v2
3028
+
3029
+ # autoscale configuration
3030
+ $autoscaleConfig = New-AzApplicationGatewayAutoscaleConfiguration - MinCapacity 3
3031
+
3032
+ # Create Application Gateway
3033
+ $appgw = New-AzApplicationGateway - Name $appgwName - ResourceGroupName $rgname - Zone 1 , 2 - Location $location - Probes $probeHttp - BackendAddressPools $pool - BackendHttpSettingsCollection $poolSetting01 - FrontendIpConfigurations $fipconfig - GatewayIpConfigurations $gipconfig - FrontendPorts $fp01 - HttpListeners $listener01 - RequestRoutingRules $rule01 - Sku $sku - TrustedRootCertificate $trustedRoot01 - AutoscaleConfiguration $autoscaleConfig - PrivateLinkConfiguration $privateLinkConfiguration
3034
+
3035
+ # Get Application Gateway
3036
+ $getgw = Get-AzApplicationGateway - Name $appgwName - ResourceGroupName $rgname
3037
+
3038
+ # Operational State
3039
+ Assert-AreEqual " Running" $getgw.OperationalState
3040
+
3041
+ # Verify PrivateLink Configuration
3042
+ Assert-NotNull $getgw.PrivateLinkConfigurations
3043
+ Assert-AreEqual 1 $getgw.PrivateLinkConfigurations.Count
3044
+ $getPrivateLinkConfig = Get-AzApplicationGatewayPrivateLinkConfiguration - Name $privateLinkConfigName - ApplicationGateway $getgw
3045
+ Assert-NotNull $getPrivateLinkConfig
3046
+ Assert-AreEqual $getPrivateLinkConfig.IpConfigurations.Count 1
3047
+
3048
+ # Get Private Link Resource
3049
+ $privateLinkResource = Get-AzPrivateLinkResource - PrivateLinkResourceId $getgw.Id
3050
+ Assert-AreEqual $privateLinkResource.Name $fipconfigName
3051
+ Assert-AreEqual $privateLinkResource.GroupId $fipconfigName
3052
+
3053
+ # Create the private endpoint resource group, vnet and subnet
3054
+ $peRg = New-AzResourceGroup - Name $peRgName - Location $location - Tags @ { testtag = " APPGw PrivateEndpoint tag" }
3055
+ $peSubnet = New-AzVirtualNetworkSubnetConfig - Name $peSubnetName - AddressPrefix 20.0 .1.0 / 24 - PrivateEndpointNetworkPolicies " Disabled"
3056
+ $peVnet = New-AzVirtualNetwork - Name $peVnetName - ResourceGroupName $peRgName - Location $location - AddressPrefix 20.0 .0.0 / 16 - Subnet $peSubnet
3057
+ $peVnet = Get-AzVirtualNetwork - Name $peVnetName - ResourceGroupName $peRgName
3058
+ $peSubnet = Get-AzVirtualNetworkSubnetConfig - Name $peSubnetName - VirtualNetwork $peVnet
3059
+
3060
+ # Set Private Endpoint Connection in memory
3061
+ $connection = New-AzPrivateLinkServiceConnection - Name $peConnName - PrivateLinkServiceId $getgw.Id - GroupId $privateLinkResource.GroupId
3062
+ $privateEndpoint = New-AzPrivateEndpoint - ResourceGroupName $peRgName - Name $peName - Location $location - Subnet $peSubnet - PrivateLinkServiceConnection $connection - ByManualRequest
3063
+
3064
+ # Get Private Endpoint and verify
3065
+ $privateEndpoint = Get-AzPrivateEndpoint - ResourceGroupName $peRgName - Name $peName
3066
+ Assert-AreEqual " Succeeded" $privateEndpoint.ProvisioningState
3067
+
3068
+ # Verify PrivateEndpointConnections using appgw Id
3069
+ $connection = Get-AzPrivateEndpointConnection - PrivateLinkResourceId $getgw.Id
3070
+ Assert-AreEqual 1 $connection.Count
3071
+ Assert-NotNull $connection.PrivateEndpoint
3072
+ Assert-NotNull $connection.PrivateLinkServiceConnectionState
3073
+ Assert-AreEqual $privateEndpoint.Id $connection.PrivateEndpoint.Id
3074
+ Assert-AreEqual " Pending" $connection.PrivateLinkServiceConnectionState.Status
3075
+
3076
+ # Verify PrivateEndpointConnections using connection Id
3077
+ $connection = Get-AzPrivateEndpointConnection - ResourceId $connection.Id
3078
+ Assert-NotNull $connection.PrivateEndpoint
3079
+ Assert-NotNull $connection.PrivateLinkServiceConnectionState
3080
+ Assert-AreEqual $privateEndpoint.Id $connection.PrivateEndpoint.Id
3081
+ Assert-AreEqual " Pending" $connection.PrivateLinkServiceConnectionState.Status
3082
+
3083
+ # Verify PrivateEndpointConnections on Application Gateway
3084
+ $getgw = Get-AzApplicationGateway - Name $appgwName - ResourceGroupName $rgname
3085
+ Assert-AreEqual 1 $getgw.PrivateEndpointConnections.Count
3086
+ $connection = $getgw.PrivateEndpointConnections
3087
+
3088
+ # Approve Connection
3089
+ $approve = Approve-AzPrivateEndpointConnection - ResourceId $connection.Id
3090
+ Assert-NotNull $approve ;
3091
+ Assert-AreEqual " Approved" $approve.PrivateLinkServiceConnectionState.Status
3092
+ Start-Sleep - s 30
3093
+
3094
+ # Deny Connection
3095
+ $deny = Deny-AzPrivateEndpointConnection - ResourceId $connection.Id
3096
+ Assert-NotNull $deny ;
3097
+ Assert-AreEqual " Rejected" $deny.PrivateLinkServiceConnectionState.Status
3098
+ Start-Sleep - s 30
3099
+
3100
+ # Remove Connection
3101
+ $remove = Remove-AzPrivateEndpointConnection - ResourceId $connection.Id - Force
3102
+ Start-Sleep - s 30
3103
+
3104
+ # Verify PrivateEndpointConnections on Application Gateway
3105
+ $getgw = Get-AzApplicationGateway - Name $appgwName - ResourceGroupName $rgname
3106
+ Assert-AreEqual 0 $getgw.PrivateEndpointConnections.Count
3107
+
3108
+ # Delete Application Gateway
3109
+ Remove-AzApplicationGateway - Name $appgwName - ResourceGroupName $rgname - Force
3110
+ }
3111
+ finally
3112
+ {
3113
+ # Cleanup
3114
+ Clean - ResourceGroup $peRgName
3115
+
3116
+ # Cleanup
3117
+ Clean - ResourceGroup $rgname
3118
+ }
3119
+ }
0 commit comments