The issue is that the create payload for VMs does not include the property osType, which is evaluated in the "if" condition the Policy, which makes Policy see the resource as not applicable for a deployment until later.
Solution
The solution is to check on the image reference, and this PR shows 1 way of doing exactly that.
Other relevant info
The policy works fine "as is" for manually remediating and will also be triggered by any change to the VM (for example a resize).
Policy will not work when deploying a new VM, because of the "if" condition.
Explanation
The issue is that the create payload for VMs does not include the property osType, which is evaluated in the "if" condition the Policy, which makes Policy see the resource as not applicable for a deployment until later.
Solution
The solution is to check on the image reference, and this PR shows 1 way of doing exactly that.
Other relevant info
The policy works fine "as is" for manually remediating and will also be triggered by any change to the VM (for example a resize).