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
436 stars 243 forks source link

WARNING: Error, continue deployment: 201 #677

Closed arrerezai closed 5 months ago

arrerezai commented 5 months ago

Discussed in https://github.com/Azure/enterprise-azure-policy-as-code/discussions/675

Originally posted by **arrerezai** June 17, 2024 Updating from early v10 to v10.3.3, I am experiencing some odd behavior when assigning new roles (although stating 201, which in itself is fine). Below is a picture from the Deploy Role Assignments step where all new roles have this message in yellow presented: ![image](https://github.com/Azure/enterprise-azure-policy-as-code/assets/157028889/5fffba49-520c-4c65-9f15-3106054598cb) When I look it up in the PS script disposed by Epac, the [Set-AzRoleAssignmentRestMethod.ps1](https://dev.azure.com/billerudkorsnas/Infrastructure/_git/azure-policies?path=/Scripts/Helpers/RestMethods/Set-AzRoleAssignmentRestMethod.ps1&_a=contents&version=GBmain) has a section called "Process response". Looks to me that this section is being called although status code 201 should not be processed at all by that if-statement that says it only cares about status codes <200 or >=300. ![image](https://github.com/Azure/enterprise-azure-policy-as-code/assets/157028889/2367f9a2-2a32-45a9-b185-15e088dadc6f) Any thoughts why this is being shown?
anwather commented 5 months ago

Looks like a recent change has messed with the logic in that block, it was update to provide a message when a scope was locked but the check for status code value got removed. Need to fix it up

arrerezai commented 5 months ago

Well, you'll be fine if you bring back the first if statement, checking for any status codes outside of 200-299 and then closing the curly bracket at the very bottom such that the else statements are all located within the first if statement. This way, no status codes between 200-299 will ever be processed by that block, which is literally what we wish for. Change is proposed above through a PR.