azureterraformazure-web-app-servicecontainers

Azure Web App publishing model container option not working with Terraform


I want to create a web app with a container as a publishing model using Terraform. The only option I found in Terraform docs was to use the azurerm_linux_web_app resource with block application_stack but I got the error that this is an unsupported block type. How can I tell Azure to provision a web app with a container not a code publishing model using Terraform? I have a docker image that is publically accessible and I will reference that in my app service. I really appreciate any help you can provide.

my terraform version is v1.9.2
my hashicorp/azurerm is ~> 3.0

Error:

│ Error: Unsupported block type
│ 
│   on main.tf line 122, in resource "azurerm_linux_web_app" "app":
│  122:   application_stack{
│ 
│ Blocks of type "application_stack" are not expected here.

main.tf

resource "azurerm_linux_web_app" "app" {
  name                = "${var.app_service_name_prefix}${random_string.random.result}"
  location            = data.azurerm_resource_group.rg.location
  resource_group_name = data.azurerm_resource_group.rg.name
  service_plan_id     = azurerm_service_plan.asp.id

  application_stack{
    docker_image_name = var.docker_image_name
    docker_registry_url = var.docker_registry_url
  }

  app_settings = {
    "STORAGE_CONNECTION_STRING"  = azurerm_storage_account.storage.primary_connection_string
  }

}

Solution

  • Error:Unsupported block type

    Application_stack block is only supported in older versions of terraform azurerm provider. As a workaround to provision a web app with a container docker image, you can include linux_fx_version = "DOCKER|<dockerimage>" under site_config = {} block as shown below.

    Refer SO by @Nancy Xiong for the relevant approach.

    terraform {
      required_providers {
        azurerm = {
          source = "hashicorp/azurerm"
          version = "3.112.0"
        }
      }
    }
    provider "azurerm"{
    features{}
    }
    data "azurerm_resource_group" "main" {
     name = "Jahnavi"
     }
     resource "azurerm_service_plan" "example" {
      name                = "example"
      resource_group_name = data.azurerm_resource_group.main.name
      location            = data.azurerm_resource_group.main.location
      os_type             = "Linux"
      sku_name            = "P1v2"
    }
    
    resource "azurerm_linux_web_app" "app" {
      name                = "examplejahapps"
      location            = data.azurerm_resource_group.main.location
      resource_group_name = data.azurerm_resource_group.main.name
      service_plan_id     = azurerm_service_plan.example.id
      site_config{
        linux_fx_version = "DOCKER|<dockerimagepath>"
      }
    }
    

    enter image description here

    enter image description here