Your company is designing a monitoring solution for resources deployed in Azure. You need to ensure that all newly created Azure Key Vaults automatically have diagnostic settings enabled to route logs to a centralized Log Analytics workspace. If a Key Vault is deployed without diagnostic settings, the settings must be created automatically without preventing the deployment of the Key Vault itself. Which Azure Policy effect should you select to meet these requirements?
- Create an Azure Policy with the DeployIfNotExists effect to configure diagnostic settings automatically.Answer
- BCreate an Azure Policy with the Deny effect to prevent Key Vault deployment unless diagnostic settings are already configured.
- CDeploy a separate Log Analytics workspace for each individual Key Vault and manually configure the settings by assigning permissions directly to developer user accounts.
- DCreate an Azure Policy with the Audit effect to flag non-compliant Key Vaults, and deploy a new Log Analytics workspace for every new resource group to keep workspaces isolated.
Answer
Create an Azure Policy with the DeployIfNotExists effect to configure diagnostic settings automatically.
The correct answer is to use the DeployIfNotExists policy effect. In Azure Policy, when you need to ensure that a resource (such as a Key Vault) has a diagnostic setting configured, but you do not want to block the deployment of the resource itself, DeployIfNotExists is the standard effect. It checks if the diagnostic setting sub-resource exists. If it does not, the policy runs a template deployment to create the diagnostic setting and route logs to the central Log Analytics workspace.
Step-by-Step Solution
Key Concept
Automating log routing and diagnostic setting enforcement using Azure Policy effects.