【问题标题】:How to deploy an App Service Extension via Terraform or ARM?如何通过 Terraform 或 ARM 部署应用服务扩展?
【发布时间】:2019-10-05 00:01:39
【问题描述】:

我们正在为我们的 AppService 使用 扩展。如何通过 ARM 模板和/或 Terraform 自动添加它?我在 Azure 为应用或服务计划生成的 ARM 模板中找不到它。

谢谢!

【问题讨论】:

  • 所以,我的理解是扩展只是 NuGet,因此如果您将所需的 NuGet 添加到项目中(在开发时,在 Visual Studio 中),此 NuGet 将在部署期间包含。 ARM 用于环境设置,这已经是代码依赖项。我猜他们提供了这个,以防你直接在 azure 中编写一些东西以进行快速测试,但可能你不应该依赖这个。
  • 我们使用这个扩展来确保我们的 dot net core 代码在 64 位环境中运行。只是在 Azure 门户应用程序设置(切换开关)中将其切换为 64 位并不能使其以 64 位运行,直到我们添加此扩展。该项目的目标是“任何 CPU”,所以我认为它是否在 x86 或 x64 中运行取决于主机。不知何故,通过添加这个扩展,我强迫它在 x64 中运行。我可以看到主机应用服务同时安装了 x86 和 x64 dotnet.exe,但如果没有扩展,我无法使其在 x64 中工作。

标签: azure terraform arm-template


【解决方案1】:

这是您可以参考的模板,根据需要使用参数 extensionName AspNetCoreRuntime.2.2.x64 和 extensionVersion 2.2.0-preview3-35497。您可以在Azure Resource Explorer 中找到扩展信息。

{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-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": [
       {
           "type": "Microsoft.Web/sites/siteextensions",
           "name": "[concat(parameters('siteName'), '/', parameters('extensionName'))]",
           "apiVersion": "2015-04-01",
           "location": "[resourceGroup().location]",
           "properties": {
               "version": "[parameters('extensionVersion')]"
           }
       }
   ]
}

结果:

您也可以在 Terraform 中使用 ARM 模板。您可以在main.tf 中添加一个azurerm_deployment_template 块。是这样的

resource "azurerm_template_deployment" "extension" {
  name                = "extension"
  resource_group_name = "${azurerm_resource_group.main.name}"
  template_body       = "${file("arm/siteextensions.json")}"

  parameters {
    "siteName"          = "${azurerm_app_service.main.name}"
    "extensionName"     = "AspNetCoreRuntime.2.2.x64"
    "extensionVersion"  = "2.2.0-preview3-35497"
  }

  deployment_mode     = "Incremental"
}

你可以从这个博客获得更多关于applying Azure App Service extensions with ARM的细节

【讨论】:

  • 谢谢!我之前浏览过一次博客,在资源浏览器中找不到值。如果我从门户手动添加扩展,我仍然无法在资源浏览器中找到 ARM 部分。但是,如果我最初使用 Terraform/ARM 模板添加它,那么我可以在 subscriptions > [mySubscription] > resourceGroups > [myResourceGroup] > providers > Microsoft.Resources > deployments > extension > operations 下找到它。不管怎样,最后我还是用 Terraform 和 ARM 模板做到了。
猜你喜欢
  • 2020-07-22
  • 2021-03-20
  • 2023-01-17
  • 1970-01-01
  • 2020-06-26
  • 2021-11-05
  • 1970-01-01
  • 2021-04-01
  • 2021-01-13
相关资源
最近更新 更多