4

I create a Diagnostic Settings for a KeyVault resource in Azure portal. DS properties are Metrics = AllMetrics and Destination is a predefined Log Analytics Workspace. When I do an export (Automation - Export Template) from Portal, nothing from the diagnostic setting is included in the generated ARM json. I've noticed the same behavior when resource is an App Service.

Is this by design? A bug? Any other way to get the ARM json for the diagnostic setting I've defined?

Caad9Rider
  • 654
  • 1
  • 8
  • 16
  • If the answer was helpful, Please [Accept it as an Answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work), so that others who encounter the same issue can find this solution and fix their problem. – Ansuman Bal Dec 17 '21 at 08:41

1 Answers1

2

I tried the same in my environment and seems we cannot export the diagnostics settings for any service like key vault, app service , storage account etc when we try to export the template for automation . But there are some sample Diagnostics settings Templates for few resources provided in Microsoft Documentation.

So , as per your settings it will something like below which I have tested by deploying :

{
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "settingName": {
                "type": "String",
                "defaultValue": "testdsansuman"
            },
            "vaultName": {
                "type": "String",
                "defaultValue": "ansumantestkv1234"
            },
            "workspaceName": {
                "type": "String",
                "defaultValue": "ansumantestlog"    
            } 
        },
        "resources": [
            {
              "type": "Microsoft.KeyVault/vaults/providers/diagnosticSettings",
              "apiVersion": "2017-05-01-preview",
              "name": "[concat(parameters('vaultName'), '/Microsoft.Insights/', parameters('settingName'))]",
              "dependsOn": [],
              "properties": {
                "workspaceId": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('WorkspaceName'))]",
                
                "metrics": [
                  {
                    "category": "AllMetrics",
                    "enabled": true
                  }
                ]
              }
            }
        ]
    }

Output:

enter image description here

enter image description here

enter image description here

enter image description here

Caad9Rider
  • 654
  • 1
  • 8
  • 16
Ansuman Bal
  • 9,705
  • 2
  • 10
  • 27
  • @Caad9Rider, you can convert the same arm template to bicep using `az bicep decompile --file main.json` command. – Ansuman Bal Dec 17 '21 at 08:47
  • If you want i can add the bicep file here as well – Ansuman Bal Dec 17 '21 at 08:47
  • The intent of my question was to find out if the portal could export the diagnostic setting - which it doesn't seem to be able to... Your ARM solution seems Ok, I prefer bicep so I ended up using what is described here: https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/diagnosticsettings?tabs=bicep – Caad9Rider Dec 17 '21 at 09:47