Skip to content

Commit c079e80

Browse files
Merge pull request #234185 from simonkurtz-MSFT/patch-2
Update api-management-howto-integrate-internal-vnet-appgateway.md
2 parents fdbcad9 + 5f11bde commit c079e80

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

articles/api-management/api-management-howto-integrate-internal-vnet-appgateway.md

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ author: dlepow
99
ms.service: api-management
1010
ms.topic: how-to
1111
ms.author: danlep
12-
ms.date: 06/10/2021
13-
ms.custom: devx-track-azurepowershell,contperf-fy21q4
12+
ms.date: 04/17/2023
13+
ms.custom: engagement-fy23,devx-track-azurepowershell,contperf-fy21q4
1414

1515
---
1616
# Integrate API Management in an internal virtual network with Application Gateway
@@ -52,7 +52,7 @@ To follow the steps described in this article, you must have:
5252

5353
## Scenario
5454

55-
In this article, you learn how to use a single API Management instance for internal and external consumers and make it act as a single front end for both on-premises and cloud APIs. You'll also understand how to expose only a subset of your APIs for external consumption by using routing functionality available in Application Gateway. In the example, the APIs are highlighted in green.
55+
In this article, you learn how to use a single API Management instance for internal and external consumers and make it act as a single front end for both on-premises and cloud APIs. You'll create an API Management instance of the newer single-tenant version 2 (stv2) type. You'll also understand how to expose only a subset of your APIs for external consumption by using routing functionality available in Application Gateway. In the example, the APIs are highlighted in green.
5656

5757
In the first setup example, all your APIs are managed only from within your virtual network. Internal consumers can access all your internal and external APIs. Traffic never goes out to the internet. High-performance connectivity can be delivered via Azure ExpressRoute circuits. In the example, the internal consumers are highlighted in orange.
5858

@@ -115,7 +115,7 @@ Resource Manager requires that all resource groups specify a location. This loca
115115
116116
The following example shows how to create a virtual network by using Resource Manager. The virtual network in this example consists of separate subnets for Application Gateway and API Management.
117117
118-
1. Create network security groups (NSGs) and NSG rules for the Application Gateway and API Management subnets.
118+
1. Create a network security group (NSG) and NSG rules for the Application Gateway subnet.
119119
120120
```powershell
121121
$appGwRule1 = New-AzNetworkSecurityRuleConfig -Name appgw-in -Description "AppGw inbound" `
@@ -124,14 +124,29 @@ The following example shows how to create a virtual network by using Resource Ma
124124
$appGwRule2 = New-AzNetworkSecurityRuleConfig -Name appgw-in-internet -Description "AppGw inbound Internet" `
125125
-Access Allow -Protocol "TCP" -Direction Inbound -Priority 110 -SourceAddressPrefix `
126126
Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 443
127+
127128
$appGwNsg = New-AzNetworkSecurityGroup -ResourceGroupName $resGroupName -Location $location -Name `
128129
"NSG-APPGW" -SecurityRules $appGwRule1, $appGwRule2
130+
```
131+
132+
1. Create a network security group (NSG) and NSG rules for the API Management subnet. [API Management stv2 requires several specific NSG rules](api-management-using-with-internal-vnet.md#enable-vnet-connection).
133+
134+
```powershell
135+
$apimRule1 = New-AzNetworkSecurityRuleConfig -Name APIM-Management -Description "APIM inbound" `
136+
-Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix ApiManagement `
137+
-SourcePortRange * -DestinationAddressPrefix VirtualNetwork -DestinationPortRange 3443
138+
$apimRule2 = New-AzNetworkSecurityRuleConfig -Name AllowAppGatewayToAPIM -Description "Allows inbound App Gateway traffic to APIM" `
139+
-Access Allow -Protocol Tcp -Direction Inbound -Priority 110 -SourceAddressPrefix "10.0.0.0/24" `
140+
-SourcePortRange * -DestinationAddressPrefix "10.0.1.0/24" -DestinationPortRange 443
141+
$apimRule3 = New-AzNetworkSecurityRuleConfig -Name AllowAzureLoadBalancer -Description "Allows inbound Azure Infrastructure Load Balancer traffic to APIM" `
142+
-Access Allow -Protocol Tcp -Direction Inbound -Priority 120 -SourceAddressPrefix AzureLoadBalancer `
143+
-SourcePortRange * -DestinationAddressPrefix "10.0.1.0/24" -DestinationPortRange 6390
144+
$apimRule4 = New-AzNetworkSecurityRuleConfig -Name AllowKeyVault -Description "Allows outbound traffic to Azure Key Vault" `
145+
-Access Allow -Protocol Tcp -Direction Outbound -Priority 100 -SourceAddressPrefix "10.0.1.0/24" `
146+
-SourcePortRange * -DestinationAddressPrefix AzureKeyVault -DestinationPortRange 443
129147
130-
$apimRule1 = New-AzNetworkSecurityRuleConfig -Name apim-in -Description "APIM inbound" `
131-
-Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix `
132-
ApiManagement -SourcePortRange * -DestinationAddressPrefix VirtualNetwork -DestinationPortRange 3443
133148
$apimNsg = New-AzNetworkSecurityGroup -ResourceGroupName $resGroupName -Location $location -Name `
134-
"NSG-APIM" -SecurityRules $apimRule1
149+
"NSG-APIM" -SecurityRules $apimRule1, $apimRule2, $apimRule3, $apimRule4
135150
```
136151
137152
1. Assign the address range 10.0.0.0/24 to the subnet variable to be used for Application Gateway while you create a virtual network.
@@ -164,6 +179,13 @@ The following example shows how to create a virtual network by using Resource Ma
164179
165180
The following example shows how to create an API Management instance in a virtual network configured for internal access only.
166181
182+
1. API Management stv2 requires a public IP with a `DomainNameLabel`:
183+
184+
```powershell
185+
$apimPublicIpAddressId = New-AzPublicIpAddress -ResourceGroupName $resGroupName -name "pip-apim" -location $location `
186+
-AllocationMethod Static -Sku Standard -Force -DomainNameLabel "apim-contoso"
187+
```
188+
167189
1. Create an API Management virtual network object by using the subnet `$apimSubnetData` you created.
168190
169191
```powershell
@@ -173,10 +195,13 @@ The following example shows how to create an API Management instance in a virtua
173195
1. Create an API Management instance inside the virtual network. This example creates the service in the Developer service tier. Substitute a unique name for your API Management instance.
174196
175197
```powershell
198+
$domain = "contoso.net"
176199
$apimServiceName = "ContosoApi" # API Management service instance name, must be globally unique
177200
$apimOrganization = "Contoso" # Organization name
178-
$apimAdminEmail = "[email protected]" # Administrator's email address
179-
$apimService = New-AzApiManagement -ResourceGroupName $resGroupName -Location $location -Name $apimServiceName -Organization $apimOrganization -AdminEmail $apimAdminEmail -VirtualNetwork $apimVirtualNetwork -VpnType "Internal" -Sku "Developer"
201+
$apimAdminEmail = "[email protected]" # Administrator's email address
202+
203+
$apimService = New-AzApiManagement -ResourceGroupName $resGroupName -Location $location -Name $apimServiceName -Organization $apimOrganization `
204+
-AdminEmail $apimAdminEmail -VirtualNetwork $apimVirtualNetwork -VpnType "Internal" -Sku "Developer" -PublicIpAddressId $apimPublicIpAddressId.Id
180205
```
181206
182207
It can take between 30 and 40 minutes to create and activate an API Management instance in this tier. After the previous command succeeds, see [DNS configuration required to access internal virtual network API Management service](api-management-using-with-internal-vnet.md#dns-configuration) to confirm access to it.
@@ -188,9 +213,9 @@ To set up custom domain names in API Management:
188213
1. Initialize the following variables with the details of the certificates with private keys for the domains and the trusted root certificate. In this example, we use `api.contoso.net`, `portal.contoso.net`, and `management.contoso.net`.
189214
190215
```powershell
191-
$gatewayHostname = "api.contoso.net" # API gateway host
192-
$portalHostname = "portal.contoso.net" # API developer portal host
193-
$managementHostname = "management.contoso.net" # API management endpoint host
216+
$gatewayHostname = "api.$domain" # API gateway host
217+
$portalHostname = "portal.$domain" # API developer portal host
218+
$managementHostname = "management.$domain" # API management endpoint host
194219
$gatewayCertPfxPath = "C:\Users\Contoso\gateway.pfx" # Full path to api.contoso.net .pfx file
195220
$portalCertPfxPath = "C:\Users\Contoso\portal.pfx" # Full path to portal.contoso.net .pfx file
196221
$managementCertPfxPath = "C:\Users\Contoso\management.pfx" # Full path to management.contoso.net .pfx file
@@ -232,8 +257,8 @@ To configure a private DNS zone for DNS resolution in the virtual network:
232257
1. Create a private DNS zone and link the virtual network.
233258
234259
```powershell
235-
$myZone = New-AzPrivateDnsZone -Name "contoso.net" -ResourceGroupName $resGroupName
236-
$link = New-AzPrivateDnsVirtualNetworkLink -ZoneName contoso.net `
260+
$myZone = New-AzPrivateDnsZone -Name $domain -ResourceGroupName $resGroupName
261+
$link = New-AzPrivateDnsVirtualNetworkLink -ZoneName $domain `
237262
-ResourceGroupName $resGroupName -Name "mylink" `
238263
-VirtualNetworkId $vnet.id
239264
```
@@ -243,13 +268,13 @@ To configure a private DNS zone for DNS resolution in the virtual network:
243268
```powershell
244269
$apimIP = $apimService.PrivateIPAddresses[0]
245270
246-
New-AzPrivateDnsRecordSet -Name api -RecordType A -ZoneName contoso.net `
271+
New-AzPrivateDnsRecordSet -Name api -RecordType A -ZoneName $domain `
247272
-ResourceGroupName $resGroupName -Ttl 3600 `
248273
-PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
249-
New-AzPrivateDnsRecordSet -Name portal -RecordType A -ZoneName contoso.net `
274+
New-AzPrivateDnsRecordSet -Name portal -RecordType A -ZoneName $domain `
250275
-ResourceGroupName $resGroupName -Ttl 3600 `
251276
-PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
252-
New-AzPrivateDnsRecordSet -Name management -RecordType A -ZoneName contoso.net `
277+
New-AzPrivateDnsRecordSet -Name management -RecordType A -ZoneName $domain `
253278
-ResourceGroupName $resGroupName -Ttl 3600 `
254279
-PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
255280
```
@@ -260,7 +285,7 @@ Create a Standard public IP resource **publicIP01** in the resource group.
260285
261286
```powershell
262287
$publicip = New-AzPublicIpAddress -ResourceGroupName $resGroupName `
263-
-name "publicIP01" -location $location -AllocationMethod Static -Sku Standard
288+
-name "pip-appgateway" -location $location -AllocationMethod Static -Sku Standard
264289
```
265290

266291
An IP address is assigned to the application gateway when the service starts.
@@ -369,13 +394,13 @@ All configuration items must be set up before you create the application gateway
369394
```powershell
370395
$gatewayRule = New-AzApplicationGatewayRequestRoutingRule -Name "gatewayrule" `
371396
-RuleType Basic -HttpListener $gatewayListener -BackendAddressPool $apimGatewayBackendPool `
372-
-BackendHttpSettings $apimPoolGatewaySetting
397+
-BackendHttpSettings $apimPoolGatewaySetting -Priority 10
373398
$portalRule = New-AzApplicationGatewayRequestRoutingRule -Name "portalrule" `
374399
-RuleType Basic -HttpListener $portalListener -BackendAddressPool $apimPortalBackendPool `
375-
-BackendHttpSettings $apimPoolPortalSetting
400+
-BackendHttpSettings $apimPoolPortalSetting -Priority 20
376401
$managementRule = New-AzApplicationGatewayRequestRoutingRule -Name "managementrule" `
377402
-RuleType Basic -HttpListener $managementListener -BackendAddressPool $apimManagementBackendPool `
378-
-BackendHttpSettings $apimPoolManagementSetting
403+
-BackendHttpSettings $apimPoolManagementSetting -Priority 30
379404
```
380405
381406
> [!TIP]

0 commit comments

Comments
 (0)