对于我见过的将 .NET 应用程序部署到 azure 的示例,人们提到了 site_config
参数,但这似乎没有得到很好的解释 in the official docs ,只是它是可选的。所以,我只是猜测,看到 azure 的界面,这可能是运行时环境?:
我发现的大多数示例都包含以下内容:
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没有这些版本,所以有点困惑:
site_config
到底是什么?它是否指定了我们的应用程序将使用的运行时环境
?如果是,那为什么它是可选的?如果不是,那么RTE是如何指定的?
最佳答案
您可以先查看可用的节点版本进行设置。
az webapp list-runtimes
- 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
'通过应用程序设置,因为即使使用门户创建应用程序服务,也可以在该参数中看到节点版本。
使用 Windows 操作系统创建的应用服务
- 然后您可以使用此 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"
关于azure - azure terraform 中的 site_config 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73663600/