# Deploy diagnostic settings for Key Vault to Event Hub

Facts read 10 Nov 2026. Page reviewed 16 Nov 2026.

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.

```text
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](https://learn.microsoft.com/en-us/azure/governance/policy/concepts/effect-deploy-if-not-exists))
- **Test before applying:** As for every Azure Policy guardrail: [how to test before enforcing](/mechanisms/azure-policy/)
- **Mechanism:** [Azure Policy (built-in definitions)](/mechanisms/azure-policy/): Resources at the scope of the assignment (management group, subscription, resource group) and their children, except notScopes and exemptions
- **Taken from:** [open source set](https://raw.githubusercontent.com/Azure/azure-policy/master/built-in-policies/policyDefinitions/Key%20Vault/DiagnosticLog_DINE.json), 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."

## Related guardrails

- [Deny enabling and disabling AWS Config](/guardrails/aws-scp-deny-config-changes/): AWS, Service control policies (SCPs), logging and monitoring
- [Deny modifications to specific CloudTrail trails](/guardrails/aws-scp-deny-cloudtrail-trail-changes/): AWS, Service control policies (SCPs), logging and monitoring
- [Deny disabling or modifying Amazon GuardDuty](/guardrails/aws-scp-deny-guardduty-changes/): AWS, Service control policies (SCPs), logging and monitoring
- [Application Insights components should block non-Entra ingestion](/guardrails/azure-policy-appinsights-entra-ingestion/): Azure, Azure Policy (built-in definitions), logging and monitoring

## Related pages

- [Application Insights components should block non-Entra ingestion (Azure Azure Policy)](/guardrails/azure-policy-appinsights-entra-ingestion/)
- [Configure Cognitive Services accounts to disable public network access (Azure Azure Policy)](/guardrails/azure-policy-ai-disable-public-network/)
- [Configure Cognitive Services accounts to disable local authentication (Azure Azure Policy)](/guardrails/azure-policy-ai-disable-local-auth/)

## Sources

- Deploy diagnostic settings for Key Vault to Event Hub: https://raw.githubusercontent.com/Azure/azure-policy/master/built-in-policies/policyDefinitions/Key%20Vault/DiagnosticLog_DINE.json (read 10 Nov 2026)
- What it breaks: https://learn.microsoft.com/en-us/azure/governance/policy/concepts/effect-deploy-if-not-exists (read 10 Nov 2026)
- How to test it first: https://learn.microsoft.com/en-us/azure/governance/policy/concepts/assignment-structure (read 10 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://cloudgovernancetools.com/guardrails/azure-policy-keyvault-diagnostic-logs/
