5

We are using an extension for our AppService. How do I automate adding it via ARM template and/or Terraform? I cannot find it in Azure generated ARM template for the app or service plan.

Thanks!

app service extension screenshot

tridy
  • 1,166
  • 1
  • 12
  • 21
  • So, my understanding is that Extensions are just NuGets, so if you add the NuGet you need to your project (while in development, in Visual Studio), this NuGet will be included during deployment. ARMs are for environment set-up, this is already a code dependency. I guess they made this available in case you are writing something directly in azure for a quick test, but probably you should not rely on this. – Rafa May 17 '19 at 21:47
  • 1
    This extension we are using to make sure that our dot net core code runs in 64 bit environment. Just switching it in Azure portal App settings (toggle switch) to 64 bits did not make it run in 64 bits until we added this extension. The project targets "Any CPU" so I think it is up to the host if it runs it in x86 or x64. Somehow by adding this extension I forced it to run in x64. I can see that the host App Service has both x86 and x64 dotnet.exe installed, but I could not make it work in x64 without the extension. – tridy May 18 '19 at 08:40

2 Answers2

8

Here is a template you could refer to, use parameters extensionName AspNetCoreRuntime.2.2.x64 and extensionVersion 2.2.0-preview3-35497 as your desired. You could find the extension info in 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')]"
           }
       }
   ]
}

Result:

enter image description here

You also could use the ARM Template in Terraform. You could add an azurerm_deployment_template block in main.tf. It's like this

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"
}

You could get more details from this blog regarding applying Azure App Service extensions with ARM

Nancy
  • 26,865
  • 3
  • 18
  • 34
  • 1
    thanks! I went through the blog once before and could not find the value in the resource explorer. If I add the extension from the portal manually, I still cannot find the ARM part in the resource explorer. However if I initially add it with the Terraform/ARM template, then I can find it under `subscriptions > [mySubscription] > resourceGroups > [myResourceGroup] > providers > Microsoft.Resources > deployments > extension > operations`. Anyway, I managed to do it in the end with Terraform and ARM template. – tridy May 20 '19 at 11:48
2

The azurerm_template_deployment is superseded by azurerm_resource_group_template_deployment and will be deprecated.

Here's the example configuration I used to enable Datadog extension in Azure App Service for reference:

resource "azurerm_resource_group_template_deployment" "dd_extension" {
  name                = "dd-extension"
  resource_group_name = var.resource_group_name
  deployment_mode     = "Incremental"

  parameters_content = jsonencode({
    "site_name" = {
      value = var.web_app_name
    }
  })

  template_content = "${file("arm/siteextensions.json")}"
}
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "site_name": {
            "type": "string"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Web/sites/siteextensions",
            "apiVersion": "2021-01-15",
            "name": "[concat(parameters('site_name'), '/Datadog.AzureAppServices.DotNet')]",
            "location": "[resourceGroup().location]"
        }
    ]
}
phwt
  • 1,356
  • 1
  • 22
  • 42