在不设置的情况下创建容器 Web 应用 linux_fx_version

Create container web app without setting linux_fx_version

我想使用 terraform 创建一个容器网络。我也想从 github 部署它。所以我需要在那里管理 linux_fx_version 属性。当我不在 terrraform 中设置它时,部署容器时出现错误

Error: Deployment Failed with Error: Error: This is not a container web app. Please remove inputs like images and configuration-file which are only relevant for container deployment.

当我在 terraform 中设置 属性 时,terraform 会在我更改基础设施时应用此设置。

是否有任何方法可以标记基于网络应用程序容器,或者仅在未设置时设置此 属性?

如果要在提供 Azure 应用服务后设置 linux_fx_version 属性。你可以 configure a custom container for Azure App Serviceaz webapp config container set。此外,您可以使用 local-exec Provisioner 在机器上调用进程 运行 Terraform。

例如,您可以从 Docker Compose 文件提供一个 Linux 运行多个 Docker 容器的应用服务。

provisioner  "local-exec" {
 
command =<<EOT
    az webapp config set \
    --resource-group ${azurerm_resource_group.main.name} \
    --name ${azurerm_app_service.main.name} \
    --linux-fx-version "COMPOSE|${filebase64("./compose.yml")}"
    EOT
}

否则,要使用 terraform 为容器创建 Web 应用程序,您需要使用 linux_fx_version 定义容器以在启动时加载。

如果您不使用应用服务槽,并且部署是在 Terraform 之外处理的 - 可以在 Terraform 的生命周期块中使用 ignore_changes 忽略对配置中特定字段的更改,例如:

resource "azurerm_app_service" "test" {
  # ...
  site_config = {
    # ...
    linux_fx_version = "DOCKER|appsvcsample/python-helloworld:0.1.2"
  }

  lifecycle {
    ignore_changes = [
      "site_config.0.linux_fx_version", # deployments are made outside of Terraform
    ]
  }
}

有关详细信息,请阅读 examples of deploying Web App for Containers (Azure App Service) with terraform and examples of using the App Service Resources