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

使用Terraform创建Windows WebApp运行时栈却生成Windows容器服务计划的问题求助

问题排查与修复方案

我帮你看了下Terraform代码,问题的核心是你没有给azurerm_app_service_plan资源指定服务计划类型,导致Azure默认创建了容器型的Windows服务计划,而非你需要的常规Web应用服务计划。

具体修复步骤

你只需要在azurerm_app_service_plan中添加两个关键参数:kind和reserved,明确指定这是用于托管.NET运行时的常规Windows服务计划。修改后的完整代码如下:

provider "azurerm" {
  version = "= 2.69.0"
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "functoss11"
  location = "East Asia"
}

resource "azurerm_app_service_plan" "example" {
  name                = "ASP-ush-9388"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  kind                = "app"  # 明确指定为常规Web应用服务计划
  reserved            = false # Windows计划必须设为false,Linux计划为true

  sku {
    tier = "basic"
    size = "B1"
  }
}

resource "azurerm_app_service" "example" {
  name                = "newddshaikh"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  app_service_plan_id = azurerm_app_service_plan.example.id

  site_config {
    dotnet_framework_version = "v5.0"
  }
}

问题原因解释

在AzureRM Provider 2.69.0版本中,azurerm_app_service_plan的kind参数没有强制默认值为app。如果不明确指定kind = "app",Azure会默认创建支持容器部署的服务计划(对应kind = "container"),这就导致你后续创建的App Service被绑定到容器型计划上,而非你期望的.NET运行时栈环境。

加上reserved = false是因为这个参数用于区分Linux和Windows计划:Linux计划需要设为true,而Windows常规计划必须设为false,否则会出现类型不匹配的问题。

重新部署这个修改后的代码,就能得到你想要的Windows WebApp运行时栈环境了。


内容的提问来源于stack exchange,提问作者Shahzad Younis

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 23:43:12