azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

az ad group member add is not idempotent

Open riezebosch opened this issue 5 years ago • 4 comments

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug I'm running this command from an Azure DevOps pipeline as part of our infrastructure deployment and without additional care these commands fail for subsequent runs.

To Reproduce az ad group member add -g $rg --member-identity $id az ad group member add -g $rg --member-identity $id

One or more added object references already exist for the following modified properties: 'members'.

Expected behavior No error.

Environment summary

azure-cli                         2.19.1

core                              2.19.1
telemetry                          1.0.6

Extensions:
datafactory                        0.2.0
azure-devops                      0.18.0
resource-graph                     1.1.0
application-insights               0.1.5
image-copy-extension               0.0.7

Additional context I've run the same command on ubuntu, macOs and Windows. Here's my workaround: https://twitter.com/MRiezebosch/status/1359533376777179137

riezebosch avatar Feb 11 '21 08:02 riezebosch

Graph

yonzhan avatar Feb 11 '21 09:02 yonzhan

Also encountering this problem. This is at odds with how almost everything else in Azure works; commands should be idempotent.

TWolversonReply avatar Mar 14 '23 15:03 TWolversonReply

No fix for this since 2021..?!?

GY-blangers avatar Feb 23 '26 09:02 GY-blangers

Thanks for the reports, and sorry this sat so long.

This is still a valid idempotency gap for automation. Microsoft Graph returns an error when the object is already a group member, and az ad group member add currently surfaces that error rather than treating the existing membership as success.

For now, the workaround is to check membership first with az ad group member check, then add only when needed.

Keeping this open as P2 to track making az ad group member add safer for repeat pipeline runs.

MaddyMicrosoft avatar Oct 05 '26 02:10 MaddyMicrosoft