Skip to content

Commit 7b1f0fd

Browse files
committed
adding windows container terraform example
1 parent aa4d3e3 commit 7b1f0fd

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

articles/app-service/provision-resource-terraform.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ms.custom:
1616

1717
Get started with [Azure App Service](overview.md) by deploying an app to the cloud via [Terraform](/azure/developer/terraform/). When you use a free App Service tier, there's no charge to complete this quickstart.
1818

19-
Terraform allows you to define and create complete infrastructure deployments in Azure. You build Terraform templates in a human-readable format that create and configure Azure resources in a consistent, reproducible manner. This article shows you how to create a Windows app by using Terraform.
19+
Terraform allows you to define and create complete infrastructure deployments in Azure. You build Terraform templates in a human-readable format that create and configure Azure resources in a consistent, reproducible manner. This article shows you how to create an app by using Terraform.
2020

2121
## Prerequisites
2222

@@ -33,7 +33,9 @@ Terraform allows you to define and create complete infrastructure deployments in
3333

3434
## Review the template
3535

36-
This quickstart uses the following template. It deploys an App Service plan and an App Service app on Linux and a sample Node.js `Hello World` app from the [Azure Samples](https://github.com/Azure-Samples) repo.
36+
Choose the following Linux or Windows template to create an App Service plan and App Service app. Linux will create a sample Node.js `Hello World` app from the [Azure Samples](https://github.com/Azure-Samples) repo. The Windows container template will create a sample ASP.NET app from the [Microsoft Container Registry](https://mcr.microsoft.com/).
37+
38+
# [Linux](#tab/linux)
3739

3840
```hcl
3941
# Configure the Azure provider
@@ -108,6 +110,70 @@ The template defines the following four Azure resources. For further details and
108110
* [Microsoft.Web/sites/sourcecontrols](/azure/templates/microsoft.web/sites/sourcecontrols): Create an external Git deployment configuration.
109111
* [`azurerm_app_service_source_control`](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_source_control)
110112

113+
# [Windows Container](#tab/windows-container)
114+
115+
```hcl
116+
# Configure the Azure provider
117+
terraform {
118+
required_providers {
119+
azurerm = {
120+
source = "hashicorp/azurerm"
121+
version = "~>3.0.0"
122+
}
123+
}
124+
}
125+
126+
provider "azurerm" {
127+
features {}
128+
}
129+
130+
# Generate a random integer to create a globally unique name
131+
resource "random_integer" "ri" {
132+
min = 10000
133+
max = 99999
134+
}
135+
136+
# Create the resource group
137+
resource "azurerm_resource_group" "rg" {
138+
name = "rg-${random_integer.ri.result}"
139+
location = "eastus"
140+
}
141+
142+
# Create the Windows App Service Plan
143+
resource "azurerm_service_plan" "windows_appserviceplan" {
144+
name = "windows-asp-${random_integer.ri.result}"
145+
location = azurerm_resource_group.rg.location
146+
resource_group_name = azurerm_resource_group.rg.name
147+
os_type = "WindowsContainer"
148+
sku_name = "P1v3"
149+
}
150+
151+
# Create the Windows Web App with a container
152+
resource "azurerm_windows_web_app" "windows_webapp" {
153+
name = "windows-webapp-${random_integer.ri.result}"
154+
location = azurerm_resource_group.rg.location
155+
resource_group_name = azurerm_resource_group.rg.name
156+
service_plan_id = azurerm_service_plan.windows_appserviceplan.id
157+
158+
site_config {
159+
always_on = true
160+
app_command_line = ""
161+
application_stack {
162+
docker_container_name = "mcr.microsoft.com/dotnet/framework/samples"
163+
docker_container_tag = "aspnetapp"
164+
}
165+
}
166+
167+
app_settings = {
168+
DOCKER_REGISTRY_SERVER_USERNAME = ""
169+
DOCKER_REGISTRY_SERVER_PASSWORD = ""
170+
DOCKER_REGISTRY_SERVER_URL = "https://mcr.microsoft.com"
171+
WEBSITES_ENABLE_APP_SERVICE_STORAGE = "false"
172+
}
173+
}
174+
175+
```
176+
111177
For more information on how to construct Terraform templates, see [Terraform documentation](https://developer.hashicorp.com/terraform/tutorials/azure-get-started).
112178

113179
## Implement the Terraform code

0 commit comments

Comments
 (0)