azure - azure terraform 中的 site_config 配置

标签 azure terraform

对于我见过的将 .NET 应用程序部署到 azure 的示例,人们提到了 site_config 参数,但这似乎没有得到很好的解释 in the official docs ,只是它是可选的。所以,我只是猜测,看到 azure 的界面,这可能是运行时环境?:enter image description here

我发现的大多数示例都包含以下内容:

resource "azurerm_app_service" "appService" {
  app_service_plan_id = azurerm_app_service_plan.appPlan.id
  location = azurerm_resource_group.rg.location
  name = "nestjs"
  resource_group_name = azurerm_resource_group.rg.name

  site_config {
    dotnet_framework_version = "v4.0"
    remote_debugging_enabled = true
  }
}  

除了for this thread之外,我在nodejs上没有找到太多东西。 ,但是,azure没有这些版本,所以有点困惑:enter image description here

site_config 到底是什么?它是否指定了我们的应用程序将使用的运行时环境?如果是,那为什么它是可选的?如果不是,那么RTE是如何指定的?

最佳答案

您可以先查看可用的节点版本进行设置。

az webapp list-runtimes

enter image description here

  • azurerm_app_service 资源已在版本 3.0 中弃用。如果是 Windows 操作系统,请使用资源“azurerm_windows_web_app”,而 azurerm_linux_web_app对于 Linux。
  • remote_debugging_version , application_stack site_config 支持的论点之一。 block ,其中 application_stack 有此 current_stack我们可以在其中设置 runtime version 选项或应用程序堆栈设置。
  • site_config block 支持以下可选参数,其中 始终开启、api_management_api_id、app_command_line , application_stack ,...,cors http2_enabled ,ip_restriction 、remote_debugging_version等application_stack

我在 application_stack 具有 current_stack 的环境中尝试过,current_stack 是 Windows Web 应用程序的应用程序堆栈。可能的值为 dotnet、dotnetcore、node、python、php 和 java。

注意来自:windows_web_app application_stack #current_stack

Whilst this property is Optional omitting it can cause unexpected behaviour, in particular for display of settings in the Azure Portal.

current_stack 设置为节点 node_version可用于设置其版本,可以是14-lts、16-lts(可用)

NOTE: from linux_web_app#node_version : 10.x versions are deprecated and may not work for new resources.

provider "azurerm" {

  features {

resource_group {
  prevent_deletion_if_contains_resources = false
  }

}
}


resource "azurerm_resource_group" "example" {
  name     = "myrg"  
 location = "westus2"
}



resource "azurerm_service_plan" "example" {
  name                = "kaexampleplan"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku_name            = "P1v2"
  os_type             = "Windows"
}

resource "azurerm_windows_web_app" "example" {
  name                = "kaexamplewebapp"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_service_plan.example.location
  service_plan_id     = azurerm_service_plan.example.id
  

  site_config {
    always_on                 = true
    application_stack {
      current_stack  = "node"
      #node_version = "16-LTS"
      
    }

  }

  app_settings = {
    WEBSITE_NODE_DEFAULT_VERSION ="16-LTS"
  }
}

我尝试创建 ' WEBSITE_NODE_DEFAULT_VERSION '通过应用程序设置,因为即使使用门户创建应用程序服务,也可以在该参数中看到节点版本。

enter image description here

使用 Windows 操作系统创建的应用服务

enter image description here

enter image description here

  • 然后您可以使用此 cli 命令检查版本:

az webapp config appsettings list --name <webappname>--resource-group v-sakavya-Mindtree --query "[?name=='WEBSITE_NODE_DEFAULT_VERSION'].value"

  • 或者在cloudeshell中设置支持的Node.js版本来设置 WEBSITE_NODE_DEFAULT_VERSION

    az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_NODE_DEFAULT_VERSION="~16"

引用:azurerm_windows_web_app - current_stack · Issue #16222 · hashicorp/terraform-provider-azurerm · GitHub

关于azure - azure terraform 中的 site_config 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73663600/

相关文章:

使用 remote-exec 配置器时,当 instance_count 大于 2 时,Terraform 卡住

azure - Powershell Connect-AzureAD 错误 "accessing_ws_metadata_exchange_failed"

azure - 无法从 Debian 9 登录 Azure 帐户

amazon-web-services - 如何使用 Terraform 传递 AssumeRole 并将 SSM 文档与 EC2 相关联

terraform - 如何使用 Terraform 修改 Athena 的主要工作组配置?

variables - 如何使用 terraform 创建文件并将变量包含为文字?

azure - 从 Azure 中的表存储触发函数

Azure Bicep - 部署失败(冲突)对此资源或依赖资源的另一项操作正在进行中 (AnotherOperationInProgress)

c# - Azure DevOps 评论中的 Ping (@) 用户

azure - 如何使用 terraform 动态添加多个 IP 到 azure servicebus 防火墙