Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

400 error for sonarcloud_user_group_member (Resource) #91

Open
dhrapson opened this issue Aug 31, 2022 · 1 comment
Open

400 error for sonarcloud_user_group_member (Resource) #91

dhrapson opened this issue Aug 31, 2022 · 1 comment

Comments

@dhrapson
Copy link

When adding users to a SC group via sonarcloud_user_group_member (Resource) we are getting the following error message:

The AddUser request returned an error: received non 2xx status code (400): 2│ User '<uid>@gitlab' is not member of organization '<organization_key>'

Our Terraform looks like this:

data "sonarcloud_user_group_members" "members" {
  group = "Members"
}

resource "sonarcloud_user_group_member" "sonarcloud_member" {
  for_each = local.sonarcloud_to_be_added_users
  group    = data.sonarcloud_user_group.member_group.name
  login    = each.value
}

The provider is configured with the correct <organisation_key> value.
Is the expectation that we have added the user to the Organization and hence into the default Group via the SonarCloud UI first, before we can user sonarcloud_user_group_member to add the user to some other subsequent Group in SonarCloud.

We can see that adding users via the SonarCloud UI calls api/organizations/add_member, which doesn't appear to be documented https://sonarcloud.io/web_api/, nor is it implemented in the Golang Module https://github.com/reinoudk/go-sonarcloud.

@reinoudk
Copy link
Contributor

Hi @dhrapson ,

Sorry for not getting back to you on this sooner. Indeed, the sonarcloud_user_group_member expects a user to have been added to the organization beforehand. If you have set up automatic synchronization (i.e. with GitLab/GitHub/BitBucket/Azure DevOps), this is kinda done automatically, with the caveat that a users has to have logged in at least once with that integration to be a member. At least, that's how it works for GitHub.

If you have enabled automatic synchronization, you can still assign users to a group, but you'd have to filter local.sonarcloud_to_be_added_users for users that are known by SonarCloud. You can use the data.sonarcloud_user_group.members_group.users for that. I can give you an example using setunion if that would be helpful 🙂. (As a side note: the Members group is read-only and always contains all the members of the org.)

Regarding the add_member endpoint: the Golang module is generated automatically and therefore only implements API endpoints that are documented under the web_api page. I've started a branch to implement arbitrary API calls using generics, but I haven't got the time to finish that at the moment.

Let me know if that answers your question 🙂.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants