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
Initially I found Community Policy - deploy-hybrid-benefit-windows which works for Marketplace, but not for VMs without imagePublisher and imageOffer. I identified properties.storageProfile.osDisk.osType as another way to identify Windows machines.
The full policy if below, but it only works for remediation, it does not work for new deployments. What am I doing wrong?
I also found this issue, which suggests adding a licenseType to the If, but then the all resources are in compliance: https://github.com/Azure/azure-policy/issues/426 remediation does not work and new resources don't as well.
Any help is very appreciated!
{
"displayName": "Deploy Azure Hybrid Benefit for Windows.",