Terraform 无法创建 64 位 Azure 应用服务(Web 应用)

Terraform fails to create a 64-bit Azure App Service (Web app)

我正在使用 terraform 版本 0.15.5(以及 0.15.4)来配置 Azure Web App 资源。以下配置工作正常:

 site_config {
    http2_enabled             = true
    always_on                 = false
    use_32_bit_worker_process = true
  }

但是,当我使用 use_32_bit_worker_process = false 来让脚本提供一个 64 位网络应用程序时,它失败了,并且我收到以下错误消息:

2021-06-03T18:06:55.6392592Z [31m│[0m [0m[1m[31mError: [0m[0m[1mError creating App Service "gfdemogatewayapp" (Resource Group "MASKED"): web.AppsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>[0m
2021-06-03T18:06:55.6411094Z [31m│[0m [0m
2021-06-03T18:06:55.6426506Z [31m│[0m [0m[0m  with azurerm_app_service.gfgatewayapp,
2021-06-03T18:06:55.6427703Z [31m│[0m [0m  on main.tf line 274, in resource "azurerm_app_service" "gfgatewayapp":
2021-06-03T18:06:55.6428766Z [31m│[0m [0m 274: resource "azurerm_app_service" "gfgatewayapp" [4m{[0m[0m
2021-06-03T18:06:55.6429584Z [31m│[0m [0m
2021-06-03T18:06:55.6430461Z [31m╵[0m[0m
2021-06-03T18:06:55.6534148Z ##[error]Error: The process '/opt/hostedtoolcache/terraform/0.15.4/x64/terraform' failed with exit code 1
2021-06-03T18:06:55.6548186Z ##[section]Finishing: Terraform approve and apply

我是否遗漏了什么或者 Terraform 在 Azure 上配置 64 位 Web 应用程序资源时有问题?

更新:完整的源代码 等级为标准,SKU 大小为“F1”。

resource "azurerm_app_service_plan" "gfwebappserviceplan" {
  name                = var.gatewayserviceplanname
  location            = "${azurerm_resource_group.gf.location}"
  resource_group_name = "${azurerm_resource_group.gf.name}"

  sku {
    tier = var.gatewayserviceplanskutier
    size = var.gatewayserviceplanskusize
  }
}
resource "azurerm_app_service" "gfgatewayapp" {
  name                = var.gatewayappname
  location            = "${azurerm_resource_group.gf.location}"
  resource_group_name = "${azurerm_resource_group.gf.name}"
  app_service_plan_id = azurerm_app_service_plan.gfwebappserviceplan.id
  app_settings = {
    APPINSIGHTS_INSTRUMENTATIONKEY = "${azurerm_application_insights.gfapplicationinsights.instrumentation_key}"
  }

  site_config {
    http2_enabled             = true
    always_on                 = false
    use_32_bit_worker_process = false
  }
}

output "gfgatewayhostname" {
  value = "${azurerm_app_service.gfgatewayapp.default_site_hostname}"
  description = "Gateway default host name"
}

resource "azurerm_template_deployment" "webapp-corestack" {
  # This will make it .NET CORE for Stack property, and add the dotnet core logging extension
  name                = "AspNetCoreStack"
  resource_group_name = "${azurerm_resource_group.gf.name}"
  template_body       = <<DEPLOY
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "siteName": {
            "type": "string",
            "metadata": {
                "description": "The Azure App Service Name"
            }
        },
        "extensionName": {
            "type": "string",
            "metadata": {
                "description": "The Site Extension Name."
            }
        },
        "extensionVersion": {
            "type": "string",
            "metadata": {
                "description": "The Extension Version"
            }
        }
    },
    "resources": [
        {
            "apiVersion": "2018-02-01",
            "name": "[parameters('siteName')]",
            "type": "Microsoft.Web/sites",
            "location": "[resourceGroup().location]",
            "properties": {
                "name": "[parameters('siteName')]",
                "siteConfig": {
                    "appSettings": [],
                    "metadata": [
                        {
                            "name": "CURRENT_STACK",
                            "value": "dotnetcore"
                        }
                    ]
                }
            }
        },
        {
            "type": "Microsoft.Web/sites/siteextensions",
            "name": "[concat(parameters('siteName'), '/', parameters('extensionName'))]",
            "apiVersion": "2018-11-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "version": "[parameters('extensionVersion')]"
            }
        }
    ]
}
  DEPLOY
  parameters = {
    "siteName"         = azurerm_app_service.gfgatewayapp.name
    "extensionName"    = "Microsoft.AspNetCore.AzureAppServices.SiteExtension"
    "extensionVersion" = "3.1.7"
  }
  deployment_mode = "Incremental"
  depends_on      = [azurerm_app_service.gfgatewayapp]
}

您收到此错误是因为您使用的是 F1 层级 app service planFreeShared 层没有 64 位选项。

Terraform AzureRM Registry

因为这是您搜索

时得到的第一个 google 结果

"AppsClient#CreateOrUpdate: Failure sending request: StatusCode=0"

那是我的错误,我会尽力帮助可能遇到这个问题的其他人。
我所做的是将函数从 azure 提供程序版本 2.x 迁移到 3.x。由于 terraform 实际上将资源类型从 azurerm_function_app 更改为 azurerm_windows_function_app,他们还更改了一些属性。
对我来说发生的事情是他们将属性 application_insights_keyapplication_insights_connection_string 添加到 site_config。在您必须手动(在 app_settings 中)添加一个名为 APPINSIGHTS_INSTRUMENTATIONKEY 的键之前。 我使用了新设置但忘记删除手动添加的键并且我的函数创建失败并出现上述错误(如果你问我不是很详细)。

我花了一些时间才弄明白,所以我在这里分享这个。

如果将 use_32_bit_worker_processuse_32_bit_worker 设置为 true 没有帮助,则尝试 运行 terraform with logging。可以通过设置 TF_LOG 环境变量来启用日志记录,例如:

$ TF_LOG=debug terraform apply

这将产生大量日志记录,包括来自 Azure 的 HTTP 响应。最后记录的响应之一应该包括有关原因的更多详细信息。就我而言,这是因为免费计划不支持 always_on,但默认情况下启用:

HTTP/2.0 409 Conflict
<snip>
{"Code":"Conflict","Message":"There was a conflict. AlwaysOn cannot be set for this site as the plan does not allow it. [...]}