Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding example for web app running on docker #115

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions quickstart/201-web-app-on-docker-container/.terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
formatter: "markdown table"

content: |-
{{ .Resources }}
{{ .Inputs }}
{{ .Providers }}
{{ .Requirements }}

output:
file: readme.html.markdown
mode: inject
71 changes: 71 additions & 0 deletions quickstart/201-web-app-on-docker-container/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -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
}
80 changes: 80 additions & 0 deletions quickstart/201-web-app-on-docker-container/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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-linux"
location = azurerm_resource_group.default.location
resource_group_name = azurerm_resource_group.default.name
sku_name = "P1v3"
os_type = "Linux"
}

resource "azurerm_service_plan" "default_windows" {
name = "${var.name_prefix}-sp-windows"
location = azurerm_resource_group.default.location
resource_group_name = azurerm_resource_group.default.name
sku_name = "P1v3"
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" = ""
xiaxyi marked this conversation as resolved.
Show resolved Hide resolved
"DOCKER_REGISTRY_SERVER_PASSWORD" = ""
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"
}
site_config {
application_stack {
docker_image = "testimage"
docker_image_tag = "latest"
}
}
}

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 = "testimage"
docker_container_tag = "latest"
}
}
}


13 changes: 13 additions & 0 deletions quickstart/201-web-app-on-docker-container/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_version = ">=1.0"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.8"
}
}
}
provider "azurerm" {
features {}
}
46 changes: 46 additions & 0 deletions quickstart/201-web-app-on-docker-container/readme.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Azure Windows/ Linux Web App running on Docker Container

This template deploys an Azure Function App running on Docker Container

<!-- Run the following commands on your Windows machine to update document -->
<!-- docker run --rm -v ${pwd}:/src -w /src mcr.microsoft.com/azterraform:latest terraform-docs markdown table --output-file readme.html.markdown --output-mode inject ./ -->
<!-- docker run --rm -v ${pwd}:/src -w /src mcr.microsoft.com/azterraform:latest markdown-table-formatter readme.html.markdown -->
<!-- Run the following command to lint Terraform code with tflint -->
<!-- docker run --rm -v ${pwd}:/src -w /src mcr.microsoft.com/azterraform:latest tflint --config=.tflint.hcl -->
<!-- Run the following command to lint Terraform code with Checkov -->
<!-- docker run --rm -v ${pwd}:/src -w /src mcr.microsoft.com/azterraform:latest checkov --skip-framework dockerfile --quiet -d ./ -->
<!-- -->
<!-- BEGIN_TF_DOCS -->
## Resources

| 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.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app) | resource |
## Inputs

| Name | Description | Type | Default | Required |
|-----------------------------------------------------------------------|---------------------------------------|----------|---------------|:--------:|
| <a name="input_location"></a> [location](#input\_location) | Location to deploy the resource group | `string` | `"West US 2"` | no |
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | Prefix of the resource name | `string` | n/a | yes |
## Providers

| Name | Version |
|---------------------------------------------------------------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | ~>3.8 |
## Requirements

| Name | Version |
|---------------------------------------------------------------------------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >=1.0 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | ~>3.8 |
<!-- END_TF_DOCS -->

## 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).
10 changes: 10 additions & 0 deletions quickstart/201-web-app-on-docker-container/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "name_prefix" {
type = string
description = "Prefix of the resource name"
}

variable "location" {
type = string
description = "Location to deploy the resource group"
default = "West US 2"
}