1
votes

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?

1
If the answer was helpful, Please Accept it as an Answer, so that others who encounter the same issue can find this solution and fix their problem.AnsumanBal-MT

1 Answers

0
votes

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"

        } //,
        //"storageAccountId": {
        //    "type": "String"
        //},
        //"eventHubAuthorizationRuleId": {
        //    "type": "String"
        //},
        //"eventHubName": {
        //    "type": "String"
        //}

    },
    "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'))]",
            //"storageAccountId": "[parameters('storageAccountId')]",
            //"eventHubAuthorizationRuleId": "[parameters('eventHubAuthorizationRuleId')]",
            //"eventHubName": "[parameters('eventHubName')]",
            //"logs": [
              //{
                //"category": "AuditEvent",
                //"enabled": true
              //}
            //],
            "metrics": [
              {
                "category": "AllMetrics",
                "enabled": true
              }
            ]
          }
        }
    ]
}

Output:

enter image description here

enter image description here

enter image description here

enter image description here