terraform-provider-azuread: azuread: GroupsClient.BaseClient.Post(): unexpected status 400 with OData error: Request_BadRequest: Request contains a property with duplicate values.
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritise this request
- Please do not leave “+1” or “me too” comments, they generate extra noise for issue followers and do not help prioritise the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and AzureAD Provider) Version
Terraform 1.0.2 Azuread 2.6.0
Affected Resource(s)
azuread_group
Terraform Configuration Files
terraform{
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>2.80.0"
}
azuread = {
source = "hashicorp/azuread"
version = "~> 2.6.0"
}
}
}
data "azuread_client_config" "current" {}
resource "azuread_group" "example" {
display_name = "example"
owners = [data.azuread_client_config.current.object_id]
security_enabled = true
}
Debug Output
https://gist.github.com/kyrios/142a0ba5350047f3ec9611ea8fe2a05d
Expected Behavior
No error
Actual Behavior
GroupsClient.BaseClient.Post(): unexpected status 400 with OData error: Request_BadRequest: Request contains a property with duplicate │ values.
Steps to Reproduce
terraform init
terraform apply
Important Factoids
We have been upgrading to 2.6.0 because of https://github.com/hashicorp/terraform-provider-azuread/issues/588
References
https://github.com/hashicorp/terraform-provider-azuread/issues/588
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 59
- Comments: 24 (7 by maintainers)
I hit this with #567. My workaround is to assign someone other than myself as an
owner
of the Azure AD group. Terraform then successfully creates the AAD group and automatically makes my ID an owner as well as the other individual I specified. It got me past this “duplicate values” error.I faced the same error and was able to “fix” it by assigning the authenticated user principal to the directory role
Groups Administrator
as stated in the documentationIf anyone comes across this issue, this did it for me (little dirty but can live with that code until this is fixed) -
Hi all, since it seems there is no traction as yet with fixing this in the API, I am proposing a potential fix for this error by retrying the group creation when this error is detected and the calling principal has been specified as an owner. The workaround relies on the other side of this API bug, that the calling principal is auto-added behind the scenes and the group is subsequently returned having the calling principal as an auto-appended owner.
If anyone is able to test out by compiling the provider locally from the
bugfix/group-400-owner
branch (see #1037), any such feedback will be greatly appreciated as it’s not feasible to field-test this workaround in all circumstances. Thanks!I experienced this issue when I was authenticating using a service principal.
After I gave the Group.ReadWrite.All API permission to the SPN it worked.
This is also stated in the documentation:
I must admit it isn’t the ideal solution to give such broad permissions.
In the enterprise I am working at, it is impossible for ordinary mortals to acquire such elevated rights.
My workaround for daily use in Terraform is to create the group via Azure CLI and import it into the state for further management via Terraform, e.g. like this:
(It is only the creation of the group that fails. Further modifications are working.)
That workaround seems to be working. Thanks a lot for sharing it @mlcooper!
Here is the code we are using:
I understand. Just wanted to add every last bit of information I have.
Unfortunately that is correct. We’re hoping to get some traction on this very soon but right now Terraform cannot resolve this error. I’m afraid since this doesn’t affect any of our testing tenants that our ability to experiment with this is limited, however you might try adding additional arbitrary owners to the group to see if this helps bypass this error.
The error appears to stem from specifying the calling principal as the sole owner of the group. In many cases the API assigns that same principal as the default owner in the case that none are specified, but this doesn’t appear to be universal, and the ‘duplicate’ error only seems to occur for a subset of users.