Azure / enterprise-azure-policy-as-code

Enterprise-ready Azure Policy-as-Code (PaC) solution (includes Az DevOps pipeline)
https://azure.github.io/enterprise-azure-policy-as-code/
MIT License
410 stars 216 forks source link

Policy definition attributes with null values gets striped away during deployment #619

Closed mothinthemachine closed 3 months ago

mothinthemachine commented 4 months ago

Describe the bug EPAC strips away null values in policy definition attributes during deployment, even though the null values are present in the generated plan.

To Reproduce Create a custom policy definition from the built-in policy:

/providers/Microsoft.Authorization/policyDefinitions/ffb6f416-7bd2-4488-8828-56585fef2be9

Deploy this new custom policy to Azure.

When checking the custom policy from Azure, attributes with null values are striped away from the policy definition.

For example:

The "ruleSetsMap" in the original built-in policy definition contains two attributes with null values:

"Overall secure score": null, "Overall secure score - snapshot": null,

In the custom policy definition deployed by EPAC, these two are missing.

Expected behavior

Attributes with null values should not be striped away when deployed to Azure via EPAC.

EPAC Version 10.2.1

anwather commented 3 months ago

@techlake - This is caused by the call to Remove-NullFields in Set-AzPolicyDefinitionRestMethod. Is there any need to have this in here? When I deploy the same policy just using PowerShell those null fields are created in the portal ok?

Removed the call and the policy deploys as expected.

anwather commented 3 months ago

PR in development