Reputation: 1260
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!
Upvotes: 6
Views: 3436
Reputation: 1402
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]"
}
]
}
Upvotes: 3
Reputation: 28224
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:
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
Upvotes: 8