Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


Terraform AzureRM - azurerm_linux_web_app

Guide to managing Azure App Service Linux Web Apps using Terraform.

Prerequisite

An Azure App Service Plan is required:

Declare App Service Plan

Resource Block

The local name will need setting.

resource "azurerm_linux_web_app" "<local name>" {
}

Required Arguments

The required arguments are:

name

The name of the Web App.

name = "app-<project, app or service>-<environment>-<###>"

Changing this argument will recreate the resource.

location

Specifies the location of the resource.

location = "uksouth"

To list all locations, you can run:

Get-AzLocation | select-object location

Changing this argument will recreate the resource.

resource_group_name

Specifies the resource group the resource should reside in.

resource_group_name = azurerm_resource_group.<local name>.name

Changing this argument will recreate the resource.

service_plan_id

The ID of the App Service Plan for the web app to be created in.

service_plan_id = azurerm_service_plan.<local name>.id

site_config

The site_config block must be present but can contain no arguments.

site_config {}

A site config block example is:

site_config {
  always_on           = true
  ftps_state          = "Disabled"
  minimum_tls_version = 1.2

  application_stack {
    php_version = 8.2
  }
}

These options are described in the next few sections.

always_on

This ensures your Web App remains loaded.

The Web App will unload after 20 minutes of no incoming requests. This means your visitors may have to wait whilst your app loads up again.

Valid Options include true & false.

ftps_state

Allows or disables the FTP/FTPS deployment capabilities.

Valid options are:

  • AllAllowed
  • FtpsOnly
  • Disabled

It is recommended to set this to disabled unless required.

minimum_tls_version

Specifies the mimimum TLS version required for the Web App.

Valid options are:

  • 1.0
  • 1.1
  • 1.2

The default value is 1.2.

application_stack

This block is used to declare the environment the Web App will run in.

Valid options are:

  • docker_image
    • docker_image_tag
  • dotnet_version = 3.1|5.0|6.0|7.0
  • go_version = 1.18|1.19
  • java_server = "JAVA|TOMCAT|JBOSSEAP"
    • java_server_version = # Run az webapp list-runtimes --linux for help
  • java_version = 8|11|17
  • node_version = "12-lts|14-lts|16-lts|18-lts"
  • php_version = 8.0|8.1|8.2
  • python_version = 3.7|3.8|3.9|3.10|3.11
  • ruby_version = 2.6|2.7

Optional Arguments

Some optional arguments are:

app_settings

These will be settings that are available at deployment or runtime as environment variables.

To see the full list, visit Azure App Service App Settings Reference.

An example setting is WEBSITE_RUN_FROM_PACKAGE which is used when deploying from a zip file.

app_settings = {
  WEBSITE_RUN_FROM_PACKAGE = 1
}

zip_deploy_file

This is the location of the zip file containing the website.

zip_deploy_file = "${path.cwd}/files/webapp/site.zip"

https_only

Whether to only support HTTPS connections or allow HTTP also.

Valid options include true & false.

https_only = true

tags

Set as many key value pairs that you need.

tags = {
  environment = "demo"
  source      = "terraform"
}

Example Declaration

This is an example for declaring a Linux Web App:

resource "azurerm_linux_web_app" "app-dtvlinux-001" {
  name                = "app-dtvlinux-demo-001"
  resource_group_name = "rg-webapp-demo-001"
  location            = "westus2"
  service_plan_id     = azurerm_service_plan.asp-dtvlinux-001.id
  https_only          = false
  zip_deploy_file     = "${path.cwd}/files/web_app/site.zip"
  tags                = {
    environment = "demo"
    source      = "terraform"
  }

  app_settings        = {
    WEBSITE_RUN_FROM_PACKAGE = 1
  }

  site_config {
    always_on           = true
    ftps_state          = "Disabled"
    minimum_tls_version = 1.2

    application_stack {
      php_version = 8.2
    }
  }
}

Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.