Forum Discussion
Azure Policy - Enable Hybrid Use Benefit
Hello there.
I'm struggling with a custom policy. My requirements are the following:
- Enable Hybrid Use Benefit for Microsoft.Compute/virtualMachines (properties.licenseType=Windows_Server)
- Work for both Marketplace and not-Marketplace virtual machines (ASRed, etc)
- Fix deployments that are done without it enabled
- Allow remediation of existing resources
1 Reply
The behavior you are encountering is by design. Azure Policy configured with the DeployIfNotExists effect can remediate non-compliant virtual machines after they have been created, but it does not intercept or modify new VM deployments. To enforce compliance at the time of provisioning, the policy must instead be structured with the Deny or Append effects. According to Microsoft’s official guidance, the Hybrid Use Benefit (HUB) must be explicitly specified during VM creation. Policies can subsequently enforce or remediate this setting, but they cannot automatically inject the licenseType property into new VM builds during deployment.
https://learn.microsoft.com/en-us/windows-server/get-started/azure-hybrid-benefit?tabs=azure
https://learn.microsoft.com/en-us/azure/governance/policy/concepts/effect-deploy-if-not-exists