From 30e0aec0d690ab0f8f1cb028bf4f4857a6dca24e Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Sun, 25 Sep 2022 09:31:18 +0800 Subject: [PATCH 1/4] adding example for web app running on docker --- .../201-web-app-on-docker-container/main.tf | 84 +++++++++++++++++++ .../providers.tf | 13 +++ .../readme.html.markdown | 22 +++++ .../variables.tf | 16 ++++ 4 files changed, 135 insertions(+) create mode 100644 quickstart/201-web-app-on-docker-container/main.tf create mode 100644 quickstart/201-web-app-on-docker-container/providers.tf create mode 100644 quickstart/201-web-app-on-docker-container/readme.html.markdown create mode 100644 quickstart/201-web-app-on-docker-container/variables.tf diff --git a/quickstart/201-web-app-on-docker-container/main.tf b/quickstart/201-web-app-on-docker-container/main.tf new file mode 100644 index 000000000..45f510283 --- /dev/null +++ b/quickstart/201-web-app-on-docker-container/main.tf @@ -0,0 +1,84 @@ + +data "azurerm_subscription" "current" {} + +resource "azurerm_resource_group" "default" { + name = "${var.name_prefix}-rg" + location = var.location +} + +resource "azurerm_user_assigned_identity" "default" { + name = "${var.name_prefix}-uai" + resource_group_name = azurerm_resource_group.default.name + location = azurerm_resource_group.default.location +} + +resource "azurerm_container_registry" "default" { + name = "${var.name_prefix}-acr" + resource_group_name = azurerm_resource_group.default.name + location = azurerm_resource_group.default.location + sku = "Premium" + identity { + type = "UserAssigned" + identity_ids = [ + azurerm_user_assigned_identity.default.id + ] + } +} + +resource "azurerm_service_plan" "default-linux" { + name = "${var.name_prefix}-sp" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + sku_name = "EP1" + os_type = "Linux" +} + +resource "azurerm_service_plan" "default-windows" { + name = "${var.name_prefix}-sp" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + sku_name = "EP1" + os_type = "Windows" +} + +// when setting docker container for web app, please use app_setting block to specify the container registry information such as URL and credentials, instead of docker_container_registry property in application_stack block. Service will try to locate the docker image based on linuxFxVersion/ windowsFxVersion property and they are composed following the format: DOCKER|containerRegistry/containerName:containerTag in terraform provider. +resource "azurerm_linux_web_app" "default" { + name = "${var.name_prefix}-lwa" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + service_plan_id = azurerm_service_plan.default-linux.id + app_settings = { + "DOCKER_REGISTRY_SERVER_URL" = "https://${azurerm_container_registry.default.name}.azurecr.io" + "DOCKER_REGISTRY_SERVER_USERNAME" = "" + "DOCKER_REGISTRY_SERVER_PASSWORD" = "" + "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" + } + site_config { + application_stack { + docker_image = "tftest/testimage" + docker_image_tag = "latest" + } + } +} +resource "azurerm_windows_web_app" "test" { + name = "${var.name_prefix}-wwa" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + service_plan_id = azurerm_service_plan.default-windows.id + + app_settings = { + "DOCKER_REGISTRY_SERVER_URL" = "https://index.docker.io" + "DOCKER_REGISTRY_SERVER_USERNAME" = "" + "DOCKER_REGISTRY_SERVER_PASSWORD" = "" + "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" + } + + site_config { + application_stack { + docker_container_name = "tftest/testimage" + docker_container_tag = "latest" + } + } +} + + diff --git a/quickstart/201-web-app-on-docker-container/providers.tf b/quickstart/201-web-app-on-docker-container/providers.tf new file mode 100644 index 000000000..74d8804c1 --- /dev/null +++ b/quickstart/201-web-app-on-docker-container/providers.tf @@ -0,0 +1,13 @@ +terraform { + required_version = ">=1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.8" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/201-web-app-on-docker-container/readme.html.markdown b/quickstart/201-web-app-on-docker-container/readme.html.markdown new file mode 100644 index 000000000..74a094861 --- /dev/null +++ b/quickstart/201-web-app-on-docker-container/readme.html.markdown @@ -0,0 +1,22 @@ +# Azure Windows/ Linux Web App running on Docker Container + +This template deploys an Azure Function App running on Docker Container + +## Resources + +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [azurerm_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) +- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) +- [azurerm_windows_web_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app) +- [azurerm_linux_web_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_web_app) + +## Variables + +| Name | Description | +|-|-| +| `location` | (Required) Azure Region in which to deploy these resources.| +| `name_prefix` | (Required) Prefix of the resource name.| + +## Example + +To see how to run this example, see [Create an Azure Function App using Terraform](https://docs.microsoft.com/azure/developer/terraform/create-azure-windows-linux-web-app-running-on-docker-container). \ No newline at end of file diff --git a/quickstart/201-web-app-on-docker-container/variables.tf b/quickstart/201-web-app-on-docker-container/variables.tf new file mode 100644 index 000000000..dba397eed --- /dev/null +++ b/quickstart/201-web-app-on-docker-container/variables.tf @@ -0,0 +1,16 @@ +variable "name_prefix" { + type = string + description = "Prefix of the resource name" +} + +variable "environment" { + type = "string" + description = "Name of the deployment environment" + default = "dev" +} + +variable "location" { + type = "string" + description = "Location to deploy the resource group" + default = "West US 2" +} From 66afaceb584058dd8a8d2f6cf700e8a378944869 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Mon, 26 Sep 2022 17:00:20 +0800 Subject: [PATCH 2/4] update fmt --- .../.terraform-docs.yml | 11 +++ .../.tflint.hcl | 71 +++++++++++++++++++ .../201-web-app-on-docker-container/main.tf | 12 ++-- .../readme.html.markdown | 44 +++++++++--- .../variables.tf | 8 +-- 5 files changed, 122 insertions(+), 24 deletions(-) create mode 100644 quickstart/201-web-app-on-docker-container/.terraform-docs.yml create mode 100644 quickstart/201-web-app-on-docker-container/.tflint.hcl diff --git a/quickstart/201-web-app-on-docker-container/.terraform-docs.yml b/quickstart/201-web-app-on-docker-container/.terraform-docs.yml new file mode 100644 index 000000000..45efe4754 --- /dev/null +++ b/quickstart/201-web-app-on-docker-container/.terraform-docs.yml @@ -0,0 +1,11 @@ +formatter: "markdown table" + +content: |- + {{ .Resources }} + {{ .Inputs }} + {{ .Providers }} + {{ .Requirements }} + +output: + file: readme.html.markdown + mode: inject \ No newline at end of file diff --git a/quickstart/201-web-app-on-docker-container/.tflint.hcl b/quickstart/201-web-app-on-docker-container/.tflint.hcl new file mode 100644 index 000000000..3e2ee6d62 --- /dev/null +++ b/quickstart/201-web-app-on-docker-container/.tflint.hcl @@ -0,0 +1,71 @@ +/* +THIS FILE IS GENERATED BY TFMOD-SCAFFOLD, PLEASE DO NOT MODIFY IT. +IF YOU WANT TO USE A CUSTOMIZED CONFIGURATION, PLEASE CREATE YOUR OWN AND +SET THIS FILE'S PATH TO $TFLINT_CONFIG ENVVIRONMENT VARIABLE. +*/ + +plugin "azurerm" { + enabled = true + version = "0.18.0" + source = "github.com/terraform-linters/tflint-ruleset-azurerm" +} + +rule "terraform_comment_syntax" { + enabled = true +} + +rule "terraform_deprecated_index" { + enabled = true +} + +rule "terraform_deprecated_interpolation" { + enabled = true +} + +rule "terraform_documented_outputs" { + enabled = true +} + +rule "terraform_documented_variables" { + enabled = true +} + +rule "terraform_module_pinned_source" { + enabled = true +} + +rule "terraform_module_version" { + enabled = true +} + +rule "terraform_naming_convention" { + enabled = true +} + +rule "terraform_required_providers" { + enabled = true +} + +rule "terraform_required_version" { + enabled = true +} + +rule "terraform_standard_module_structure" { + enabled = false +} + +rule "terraform_typed_variables" { + enabled = true +} + +rule "terraform_unused_declarations" { + enabled = true +} + +rule "terraform_unused_required_providers" { + enabled = true +} + +rule "terraform_workspace_remote" { + enabled = true +} \ No newline at end of file diff --git a/quickstart/201-web-app-on-docker-container/main.tf b/quickstart/201-web-app-on-docker-container/main.tf index 45f510283..059c2ca34 100644 --- a/quickstart/201-web-app-on-docker-container/main.tf +++ b/quickstart/201-web-app-on-docker-container/main.tf @@ -1,6 +1,4 @@ -data "azurerm_subscription" "current" {} - resource "azurerm_resource_group" "default" { name = "${var.name_prefix}-rg" location = var.location @@ -25,7 +23,7 @@ resource "azurerm_container_registry" "default" { } } -resource "azurerm_service_plan" "default-linux" { +resource "azurerm_service_plan" "default_linux" { name = "${var.name_prefix}-sp" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name @@ -33,7 +31,7 @@ resource "azurerm_service_plan" "default-linux" { os_type = "Linux" } -resource "azurerm_service_plan" "default-windows" { +resource "azurerm_service_plan" "default_windows" { name = "${var.name_prefix}-sp" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name @@ -41,12 +39,12 @@ resource "azurerm_service_plan" "default-windows" { os_type = "Windows" } -// when setting docker container for web app, please use app_setting block to specify the container registry information such as URL and credentials, instead of docker_container_registry property in application_stack block. Service will try to locate the docker image based on linuxFxVersion/ windowsFxVersion property and they are composed following the format: DOCKER|containerRegistry/containerName:containerTag in terraform provider. +# when setting docker container for web app, please use app_setting block to specify the container registry information such as URL and credentials, instead of docker_container_registry property in application_stack block. Service will try to locate the docker image based on linuxFxVersion/ windowsFxVersion property and they are composed following the format: DOCKER|containerRegistry/containerName:containerTag in terraform provider. resource "azurerm_linux_web_app" "default" { name = "${var.name_prefix}-lwa" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name - service_plan_id = azurerm_service_plan.default-linux.id + service_plan_id = azurerm_service_plan.default_linux.id app_settings = { "DOCKER_REGISTRY_SERVER_URL" = "https://${azurerm_container_registry.default.name}.azurecr.io" "DOCKER_REGISTRY_SERVER_USERNAME" = "" @@ -64,7 +62,7 @@ resource "azurerm_windows_web_app" "test" { name = "${var.name_prefix}-wwa" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name - service_plan_id = azurerm_service_plan.default-windows.id + service_plan_id = azurerm_service_plan.default_windows.id app_settings = { "DOCKER_REGISTRY_SERVER_URL" = "https://index.docker.io" diff --git a/quickstart/201-web-app-on-docker-container/readme.html.markdown b/quickstart/201-web-app-on-docker-container/readme.html.markdown index 74a094861..d0e34e876 100644 --- a/quickstart/201-web-app-on-docker-container/readme.html.markdown +++ b/quickstart/201-web-app-on-docker-container/readme.html.markdown @@ -2,20 +2,44 @@ This template deploys an Azure Function App running on Docker Container + + + + + + + + + ## Resources -- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) -- [azurerm_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) -- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) -- [azurerm_windows_web_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app) -- [azurerm_linux_web_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_web_app) +| Name | Type | +|--------------------------------------------------------------------------------------------------------------------------------------------------|----------| +| [azurerm_container_registry.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry) | resource | +| [azurerm_linux_web_app.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_web_app) | resource | +| [azurerm_resource_group.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource | +| [azurerm_service_plan.default_linux](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) | resource | +| [azurerm_service_plan.default_windows](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) | resource | +| [azurerm_user_assigned_identity.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity) | resource | +| [azurerm_windows_web_app.test](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app) | resource | +## Inputs -## Variables +| Name | Description | Type | Default | Required | +|-----------------------------------------------------------------------|---------------------------------------|----------|---------------|:--------:| +| [location](#input\_location) | Location to deploy the resource group | `string` | `"West US 2"` | no | +| [name\_prefix](#input\_name\_prefix) | Prefix of the resource name | `string` | n/a | yes | +## Providers -| Name | Description | -|-|-| -| `location` | (Required) Azure Region in which to deploy these resources.| -| `name_prefix` | (Required) Prefix of the resource name.| +| Name | Version | +|---------------------------------------------------------------|---------| +| [azurerm](#provider\_azurerm) | ~>3.8 | +## Requirements + +| Name | Version | +|---------------------------------------------------------------------------|---------| +| [terraform](#requirement\_terraform) | >=1.0 | +| [azurerm](#requirement\_azurerm) | ~>3.8 | + ## Example diff --git a/quickstart/201-web-app-on-docker-container/variables.tf b/quickstart/201-web-app-on-docker-container/variables.tf index dba397eed..e4c010124 100644 --- a/quickstart/201-web-app-on-docker-container/variables.tf +++ b/quickstart/201-web-app-on-docker-container/variables.tf @@ -3,14 +3,8 @@ variable "name_prefix" { description = "Prefix of the resource name" } -variable "environment" { - type = "string" - description = "Name of the deployment environment" - default = "dev" -} - variable "location" { - type = "string" + type = string description = "Location to deploy the resource group" default = "West US 2" } From 39a9fbc560dc83636eb17cc46af63adad4d16bf6 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Wed, 28 Sep 2022 11:07:23 +0800 Subject: [PATCH 3/4] update config --- .../201-web-app-on-docker-container/main.tf | 20 +++++++++---------- .../readme.html.markdown | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/quickstart/201-web-app-on-docker-container/main.tf b/quickstart/201-web-app-on-docker-container/main.tf index 059c2ca34..e700cb766 100644 --- a/quickstart/201-web-app-on-docker-container/main.tf +++ b/quickstart/201-web-app-on-docker-container/main.tf @@ -1,4 +1,3 @@ - resource "azurerm_resource_group" "default" { name = "${var.name_prefix}-rg" location = var.location @@ -11,7 +10,7 @@ resource "azurerm_user_assigned_identity" "default" { } resource "azurerm_container_registry" "default" { - name = "${var.name_prefix}-acr" + name = "${var.name_prefix}acr" resource_group_name = azurerm_resource_group.default.name location = azurerm_resource_group.default.location sku = "Premium" @@ -24,18 +23,18 @@ resource "azurerm_container_registry" "default" { } resource "azurerm_service_plan" "default_linux" { - name = "${var.name_prefix}-sp" + name = "${var.name_prefix}-sp-linux" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name - sku_name = "EP1" + sku_name = "P1v3" os_type = "Linux" } resource "azurerm_service_plan" "default_windows" { - name = "${var.name_prefix}-sp" + name = "${var.name_prefix}-sp-windows" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name - sku_name = "EP1" + sku_name = "P1v3" os_type = "Windows" } @@ -53,27 +52,26 @@ resource "azurerm_linux_web_app" "default" { } site_config { application_stack { - docker_image = "tftest/testimage" + docker_image = "testimage" docker_image_tag = "latest" } } } -resource "azurerm_windows_web_app" "test" { + +resource "azurerm_windows_web_app" "default" { name = "${var.name_prefix}-wwa" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name service_plan_id = azurerm_service_plan.default_windows.id - app_settings = { "DOCKER_REGISTRY_SERVER_URL" = "https://index.docker.io" "DOCKER_REGISTRY_SERVER_USERNAME" = "" "DOCKER_REGISTRY_SERVER_PASSWORD" = "" "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" } - site_config { application_stack { - docker_container_name = "tftest/testimage" + docker_container_name = "testimage" docker_container_tag = "latest" } } diff --git a/quickstart/201-web-app-on-docker-container/readme.html.markdown b/quickstart/201-web-app-on-docker-container/readme.html.markdown index d0e34e876..15184ad4b 100644 --- a/quickstart/201-web-app-on-docker-container/readme.html.markdown +++ b/quickstart/201-web-app-on-docker-container/readme.html.markdown @@ -21,7 +21,7 @@ This template deploys an Azure Function App running on Docker Container | [azurerm_service_plan.default_linux](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) | resource | | [azurerm_service_plan.default_windows](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) | resource | | [azurerm_user_assigned_identity.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity) | resource | -| [azurerm_windows_web_app.test](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app) | resource | +| [azurerm_windows_web_app.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app) | resource | ## Inputs | Name | Description | Type | Default | Required | From 24213c47ea333a242dfa3a2c348413b7b0ccbd46 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Thu, 20 Oct 2022 11:22:26 +0800 Subject: [PATCH 4/4] update --- quickstart/201-web-app-on-docker-container/main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quickstart/201-web-app-on-docker-container/main.tf b/quickstart/201-web-app-on-docker-container/main.tf index e700cb766..875c9a3b7 100644 --- a/quickstart/201-web-app-on-docker-container/main.tf +++ b/quickstart/201-web-app-on-docker-container/main.tf @@ -46,8 +46,8 @@ resource "azurerm_linux_web_app" "default" { service_plan_id = azurerm_service_plan.default_linux.id app_settings = { "DOCKER_REGISTRY_SERVER_URL" = "https://${azurerm_container_registry.default.name}.azurecr.io" - "DOCKER_REGISTRY_SERVER_USERNAME" = "" - "DOCKER_REGISTRY_SERVER_PASSWORD" = "" + "DOCKER_REGISTRY_SERVER_USERNAME" = "username" + "DOCKER_REGISTRY_SERVER_PASSWORD" = "password" "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" } site_config { @@ -65,8 +65,8 @@ resource "azurerm_windows_web_app" "default" { service_plan_id = azurerm_service_plan.default_windows.id app_settings = { "DOCKER_REGISTRY_SERVER_URL" = "https://index.docker.io" - "DOCKER_REGISTRY_SERVER_USERNAME" = "" - "DOCKER_REGISTRY_SERVER_PASSWORD" = "" + "DOCKER_REGISTRY_SERVER_USERNAME" = "username" + "DOCKER_REGISTRY_SERVER_PASSWORD" = "password" "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" } site_config {