You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform配置Azure Linux Web App容器发布模型报错求解决方案

解决Terraform创建Azure容器化Web App的配置错误

问题原因

你遇到的Unsupported block type错误是因为HashiCorp AzureRM Provider 3.0+版本中,azurerm_linux_web_app资源已移除application_stack块用于容器部署的用法。该块仅适用于代码部署场景(如指定Python/Node.js等运行时栈),容器部署需要使用专门的容器配置参数。

正确配置方案

直接在azurerm_linux_web_app资源中使用顶层的容器镜像参数,或通过site_config块配置更精细的容器运行参数:

基础配置(公开Docker镜像)

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

  # 核心容器配置:指定公开镜像地址和Registry URL
  docker_image        = var.docker_image_name
  docker_registry_url = var.docker_registry_url

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

进阶配置(自定义容器命令/端口)

如果需要指定容器启动命令、内部端口等,添加site_config.docker_container_settings块:

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

  docker_image        = var.docker_image_name
  docker_registry_url = var.docker_registry_url

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

  site_config {
    docker_container_settings {
      # 可选:容器启动命令
      command = "npm start"
      # 可选:容器内部监听端口(需与镜像暴露端口一致)
      ports   = "8080"
    }
  }
}

额外注意事项

  • 确保你的服务计划是Linux类型,且SKU支持容器部署(如B1、S1、P1等,Consumption SKU也支持):
resource "azurerm_service_plan" "asp" {
  name                = "your-service-plan-name"
  resource_group_name = data.azurerm_resource_group.rg.name
  location            = data.azurerm_resource_group.rg.location
  os_type             = "Linux"
  sku_name            = "B1"
}

内容的提问来源于stack exchange,提问作者Abubakar Riaz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 23:22:21