Skip to content

Commit 857b37d

Browse files
Merge pull request #313957 from msangapu-msft/patch-29
Revise terraform-secure-backend-frontend.md
2 parents 6d1acba + d9be2ee commit 857b37d

1 file changed

Lines changed: 35 additions & 30 deletions

File tree

articles/app-service/scripts/terraform-secure-backend-frontend.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,45 @@ description: Learn how to use terraform provider for App Service to deploy two w
44
author: ericgre
55
ms.assetid: 3e5d1bbd-5581-40cc-8f65-bc74f1802156
66
ms.topic: sample
7-
ms.date: 12/06/2022
7+
ms.date: 03/30/2026
88
ms.author: ericg
99
ms.service: azure-app-service
1010
ms.custom: devx-track-terraform
1111
---
1212

1313
# Create two web apps connected securely with Private Endpoint and VNet integration
1414

15-
This article illustrates an example use of [Private Endpoint](../networking/private-endpoint.md) and regional [VNet integration](../overview-vnet-integration.md) to connect two web apps (frontend and backend) securely with the following terraform configuration:
16-
- Deploy a VNet
17-
- Create the first subnet for the integration
18-
- Create the second subnet for the private endpoint, you have to set a specific parameter to disable network policies
19-
- Deploy one App Service plan of type Basic, Standard, PremiumV2, PremiumV3, IsolatedV2, Functions Premium (sometimes referred to as the Elastic Premium plan), required for Private Endpoint feature
20-
- Create the frontend web app with specific app settings to consume the private DNS zone, [more details](../overview-vnet-integration.md#azure-dns-private-zones)
21-
- Connect the frontend web app to the integration subnet
22-
- Create the backend web app
23-
- Create the DNS private zone with the name of the private link zone for web app privatelink.azurewebsites.net
24-
- Link this zone to the VNet
25-
- Create the private endpoint for the backend web app in the endpoint subnet, and register DNS names (website and SCM) in the previously created DNS private zone
15+
This article illustrates an example use of [Private Endpoint](../networking/private-endpoint.md) and regional [VNet integration](../overview-vnet-integration.md) to connect two web apps (frontend and backend) securely with the following Terraform configuration:
16+
17+
1. Deploy a VNet
18+
1. Create the first subnet for the integration
19+
1. Create the second subnet for the private endpoint, and disable subnet network policies for private endpoints (set `private_endpoint_network_policies_enabled = false`)
20+
1. Deploy one App Service plan of type Basic, Standard, PremiumV2, PremiumV3, IsolatedV2, Functions Premium (sometimes referred to as the Elastic Premium plan), required for the Private Endpoint feature
21+
1. Create the frontend web app with specific app settings to consume the private DNS zone. For more information, see [Azure DNS private zones](../overview-vnet-integration.md#azure-dns-private-zones).
22+
1. Connect the frontend web app to the integration subnet
23+
1. Create the backend web app
24+
1. Create the DNS private zone with the name of the private link zone for web apps (`privatelink.azurewebsites.net`)
25+
1. Link this zone to the VNet
26+
1. Create the private endpoint for the backend web app in the endpoint subnet, and register DNS names (site and SCM) in the previously created DNS private zone
2627

2728
## How to use terraform in Azure
2829

2930
Browse to the [Azure documentation](/azure/developer/terraform/) to learn how to use terraform with Azure.
3031

3132
## The complete terraform file
3233

33-
To use this file, replace the placeholders _\<unique-frontend-app-name>_ and _\<unique-backend-app-name>_ (app name is used to form a unique DNS name worldwide).
34+
To use this file, replace the placeholders _\<unique-frontend-app-name>_ and _\<unique-backend-app-name>_ (app name is used to form a unique DNS name worldwide).
3435

3536
```hcl
3637
terraform {
3738
required_providers {
3839
azurerm = {
39-
source = "hashicorp/azurerm"
40-
version = "~>3.0"
40+
source = "hashicorp/azurerm"
41+
version = "~> 3.0"
4142
}
4243
}
4344
}
45+
4446
provider "azurerm" {
4547
features {}
4648
}
@@ -62,8 +64,10 @@ resource "azurerm_subnet" "integrationsubnet" {
6264
resource_group_name = azurerm_resource_group.rg.name
6365
virtual_network_name = azurerm_virtual_network.vnet.name
6466
address_prefixes = ["10.0.1.0/24"]
67+
6568
delegation {
6669
name = "delegation"
70+
6771
service_delegation {
6872
name = "Microsoft.Web/serverFarms"
6973
}
@@ -75,7 +79,8 @@ resource "azurerm_subnet" "endpointsubnet" {
7579
resource_group_name = azurerm_resource_group.rg.name
7680
virtual_network_name = azurerm_virtual_network.vnet.name
7781
address_prefixes = ["10.0.2.0/24"]
78-
private_endpoint_network_policies_enabled = true
82+
83+
private_endpoint_network_policies_enabled = false
7984
}
8085
8186
resource "azurerm_service_plan" "appserviceplan" {
@@ -90,25 +95,26 @@ resource "azurerm_windows_web_app" "frontwebapp" {
9095
name = "<unique-frontend-app-name>"
9196
location = azurerm_resource_group.rg.location
9297
resource_group_name = azurerm_resource_group.rg.name
93-
service_plan_id = azurerm_service_plan.appserviceplan.id
98+
service_plan_id = azurerm_service_plan.appserviceplan.id
9499
95100
site_config {}
101+
96102
app_settings = {
97-
"WEBSITE_DNS_SERVER": "168.63.129.16",
98-
"WEBSITE_VNET_ROUTE_ALL": "1"
103+
"WEBSITE_DNS_SERVER" = "168.63.129.16"
104+
"WEBSITE_VNET_ROUTE_ALL" = "1"
99105
}
100106
}
101107
102108
resource "azurerm_app_service_virtual_network_swift_connection" "vnetintegrationconnection" {
103-
app_service_id = azurerm_windows_web_app.frontwebapp.id
104-
subnet_id = azurerm_subnet.integrationsubnet.id
109+
app_service_id = azurerm_windows_web_app.frontwebapp.id
110+
subnet_id = azurerm_subnet.integrationsubnet.id
105111
}
106112
107113
resource "azurerm_windows_web_app" "backwebapp" {
108114
name = "<unique-backend-app-name>"
109115
location = azurerm_resource_group.rg.location
110116
resource_group_name = azurerm_resource_group.rg.name
111-
service_plan_id = azurerm_service_plan.appserviceplan.id
117+
service_plan_id = azurerm_service_plan.appserviceplan.id
112118
113119
site_config {}
114120
}
@@ -119,10 +125,10 @@ resource "azurerm_private_dns_zone" "dnsprivatezone" {
119125
}
120126
121127
resource "azurerm_private_dns_zone_virtual_network_link" "dnszonelink" {
122-
name = "dnszonelink"
123-
resource_group_name = azurerm_resource_group.rg.name
128+
name = "dnszonelink"
129+
resource_group_name = azurerm_resource_group.rg.name
124130
private_dns_zone_name = azurerm_private_dns_zone.dnsprivatezone.name
125-
virtual_network_id = azurerm_virtual_network.vnet.id
131+
virtual_network_id = azurerm_virtual_network.vnet.id
126132
}
127133
128134
resource "azurerm_private_endpoint" "privateendpoint" {
@@ -132,20 +138,19 @@ resource "azurerm_private_endpoint" "privateendpoint" {
132138
subnet_id = azurerm_subnet.endpointsubnet.id
133139
134140
private_dns_zone_group {
135-
name = "privatednszonegroup"
141+
name = "privatednszonegroup"
136142
private_dns_zone_ids = [azurerm_private_dns_zone.dnsprivatezone.id]
137143
}
138144
139145
private_service_connection {
140-
name = "privateendpointconnection"
146+
name = "privateendpointconnection"
141147
private_connection_resource_id = azurerm_windows_web_app.backwebapp.id
142-
subresource_names = ["sites"]
143-
is_manual_connection = false
148+
subresource_names = ["sites"]
149+
is_manual_connection = false
144150
}
145151
}
146152
```
147153

148154
## Next steps
149155

150-
151156
> [Learn more about using Terraform in Azure](/azure/developer/terraform/)

0 commit comments

Comments
 (0)