Skip to content
Cloud Governance Tools

Deploy diagnostic settings for Key Vault to Event Hub

Deploy diagnostic settings for Key Vault to Event Hub is an Azure guardrail written in Azure Policy. Deploys diagnostic settings that stream key vault logs to an Event Hub whenever a vault without them is created or updated. Copied from a licensed open source set and read on 10 Nov 2026.

More logging and monitoring guardrails ยท About Azure Policy

Built-in policy definition: Deploy Diagnostic Settings for Key Vault to Event Hub
Definition ID: ed7c8c13-51e7-49d1-8a43-8490431a0da2
Category: Key Vault
Supported effects: DeployIfNotExists, Disabled
policyRule (copied from the repository file):
{
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.KeyVault/vaults"
        },
        {
          "anyOf": [
            {
              "value": "[parameters('eventHubLocation')]",
              "equals": ""
            },
            {
              "field": "location",
              "equals": "[parameters('eventHubLocation')]"
            }
          ]
        }
      ]
    },
    "then": {
      "effect": "[parameters('effect')]",
      "details": {
        "type": "Microsoft.Insights/diagnosticSettings",
        "name": "[parameters('profileName')]",
        "existenceCondition": {
          "allOf": [
            {
              "count": {
                "field": "Microsoft.Insights/diagnosticSettings/logs[*]",
                "where": {
                  "field": "Microsoft.Insights/diagnosticSettings/logs[*].enabled",
                  "equals": "[parameters('logsEnabled')]"
                }
              },
              "greaterOrEquals": 1
            },
            {
              "count": {
                "field": "Microsoft.Insights/diagnosticSettings/metrics[*]",
                "where": {
                  "field": "Microsoft.Insights/diagnosticSettings/metrics[*].enabled",
                  "equals": "[parameters('metricsEnabled')]"
                }
              },
              "greaterOrEquals": 1
            }
          ]
        },
        "roleDefinitionIds": [
          "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
        ],
        "deployment": {
          "properties": {
            "mode": "incremental",
            "template": {
              "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
              "contentVersion": "1.0.0.0",
              "parameters": {
                "vaultName": {
                  "type": "string"
                },
                "location": {
                  "type": "string"
                },
                "eventHubRuleId": {
                  "type": "string"
                },
                "metricsEnabled": {
                  "type": "string"
                },
                "logsEnabled": {
                  "type": "string"
                },
                "profileName": {
                  "type": "string"
                }
              },
              "resources": [
                {
                  "type": "Microsoft.KeyVault/vaults/providers/diagnosticSettings",
                  "apiVersion": "2017-05-01-preview",
                  "name": "[concat(parameters('vaultName'), '/', 'Microsoft.Insights/', parameters('profileName'))]",
                  "location": "[parameters('location')]",
                  "dependsOn": [],
                  "properties": {
                    "eventHubAuthorizationRuleId": "[parameters('eventHubRuleId')]",
                    "metrics": [
                      {
                        "category": "AllMetrics",
                        "enabled": "[parameters('metricsEnabled')]",
                        "retentionPolicy": {
                          "enabled": false,
                          "days": 0
                        }
                      }
                    ],
                    "logs": [
                      {
                        "category": "AuditEvent",
                        "enabled": "[parameters('logsEnabled')]"
                      },
                      {
                        "category": "AzurePolicyEvaluationDetails",
                        "enabled": "[parameters('logsEnabled')]"
                      }
                    ]
                  }
                }
              ],
              "outputs": {
                "policy": {
                  "type": "string",
                  "value": "[concat('Enabled diagnostic settings for ', parameters('vaultName'))]"
                }
              }
            },
            "parameters": {
              "location": {
                "value": "[field('location')]"
              },
              "vaultName": {
                "value": "[field('name')]"
              },
              "eventHubRuleId": {
                "value": "[parameters('eventHubRuleId')]"
              },
              "metricsEnabled": {
                "value": "[parameters('metricsEnabled')]"
              },
              "logsEnabled": {
                "value": "[parameters('logsEnabled')]"
              },
              "profileName": {
                "value": "[parameters('profileName')]"
              }
            }
          }
        }
      }
    }
  }
Blocks
Deploys diagnostic settings that stream key vault logs to an Event Hub whenever a vault without them is created or updated.
Breaks
DeployIfNotExists is not a blocking effect: matching resources are marked non-compliant and no action is taken on them until a remediation task runs. (source)
Test before applying
As for every Azure Policy guardrail: how to test before enforcing
Mechanism
Azure Policy (built-in definitions): Resources at the scope of the assignment (management group, subscription, resource group) and their children, except notScopes and exemptions
Taken from
open source set, MIT License, Azure/azure-policy repository, https://raw.githubusercontent.com/Azure/azure-policy/master/LICENSE

What the source says

"Deploys the diagnostic settings for Key Vault to stream to a regional Event Hub when any Key Vault which is missing this diagnostic settings is created or updated." (read 10 Nov 2026).

On what it breaks: "During an evaluation cycle, policy definitions with a DeployIfNotExists effect that match resources are marked as non-compliant, but no action is taken on that resource."

Sources

  1. Deploy diagnostic settings for Key Vault to Event Hub, read 10 Nov 2026
  2. What it breaks, read 10 Nov 2026
  3. How to test it first, read 10 Nov 2026

Last reviewed 16 Nov 2026.