如何通过Terraform或ARM部署App Service Extension?

时间:2019-05-17 16:09:31

标签: azure terraform arm-template

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

谢谢!

app service extension screenshot

1 个答案:

答案 0 :(得分: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')]"
           }
       }
   ]
}

结果:

enter image description here

您还可以在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的更多详细信息