You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
github_repository_collaborator broken since v2.8.0 #469
Since github provider v2.8.0 the github_repository_collaborator resource is broken.
It fails with User <username> is already a collaborator. In v2.7.0 this worked as expected.
The collaborator should be added to the repository and the resource should be in the state.
Actual Behavior
What actually happened?
The collaborator gets added to the repository with the correct permissions,
but terraform fails with this error and the resource is not in the state.
Error: User foobar is already a collaborator
on test.tf line 7, in resource "github_repository_collaborator""user_foobar":
7: resource "github_repository_collaborator""user_foobar" {
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform apply
Important Factoids
References
Reacted by kapuett, Kyle Christensen, Tom Patzig, Andy, leowmjw, Michal Schott, Andrew Wright, Nikolay Kolev, Youri van den Berg, Manivannan Giridharan and 12 more
hi @tpatzig, thank you for writing up this issue!
so I'm able to reproduce this with the latest release of the provider (and not in 2.7.0 as suggested) but only if the collaborator in question is also the owner/admin in the repository being created. what's the relationship of the collaborator to the repository in your case?
@jcudit I ran into the same problem under different circumstances over in #480 and I would rather expect a warning than an error. In my case the user was an organizational admin and got admin permissions automatically for the repository (check via the /repos/:owner/:repo/collaborators/:username/permission endpoint). For documentation purposes the admin was also explicitly added to the repositories collaborators where he is an active member.
Hi @anGie44, the collaborator I'm trying to add is an outside the organization collaborator.
It is not the same admin user I've configured the provider with and the repo is created with.
Hi @jcudit, I do not see, why this should fail or error at all 🤷♂️
This outside collaborator is added to that repo for the first time; it is not the owner/admin of that repo. Without that collaborator resource that user would have no permissions on that repo.
@tpatzig by outside does that also mean the user is not part of a team within the org and the org has Base Permissions set to None? I was also able to reproduce this scenario in v2.8.0 and not v2.7.0 by adding a completely new user foobar (outside org and not the user authenticated with the provider) first to a team that lives within an org (org has Base Permissions set to None so private repos are not visible from the new user's perspective even while in the team), and then I attempted to add the new user as a collaborator and got the error Error: User foobar is already a collaborator in v2.8.0
I also did some more testing on this one today. My organization also has Base Permissions set to None and I'm trying to add a user (which is already part of my organization) to a repository with Write permissions. The user gets added, but the apply fails with the error message above. Note that the user is not an organizational administrator.
Yes, with outside collaborator I mean a gh user, that is not part of the organisation (nor in any of the organisations teams) by intention. The Base Permissions of our Org is Read.
Edit: If you want the short version, @jcudit wrote it up here. My take is that the GitHub API documentation is incomplete and 204 should be accepted as an OK until it's fixed/updated. (Which means a manual check needs to happen before the collaborator is added.)
I was able to reproduce the issue with
Terraform 0.12.26
provider.github v2.8.1
Test
User is a member of the organization
User was not affiliated with the repo before (the admin was trying to add user to the repo)
During multiple tests, the user was added with "pull", "push", "triage", "maintain", "admin" permissions
Result
In each case the expected permission is set in GitHub. (Good!)
In each case, Terraform reports the "User X is already a collaborator" error. (Bad)
Additional test
I added the user to the repo as a collaborator outside of Terraform
I reran the Terraform code multiple times with different permission set
Additional Result
Terraform reported that the user is already a collaborator (Good!)
GitHub showed that the user permissions changed in line with the Terraform code (Weird/Bad from a Terraform perspective)
Troubleshooting details
According to the GitHub API description on adding collaborators, there are two possible responses to the call:
201 (and some content), if an invitation was sent to the invited GitHub user
204 if the user is already a collaborator
What the API documentation fails to mention (at least in my case), is that if a user is a member of my organization, the user will not need an invitation to be added as a collaborator to a repository within the organization.
So, my assumption is that since the user doesn't need an invite, a 201 response would be inappropriate. The only other defined response is 204 and for whatever reason, GitHub API chooses to send that in each OK case. This suspicion is further advanced by the "Remove a repository collaborator" documentation below in the API, which also responds with 204 if the collaborator was successfully removed.
In short: the GitHub API documentation fails to mention that 204 is reported in any regular case.
What's worse, it seems to execute the request properly, before reporting 204, even when the user is really a collaborator on the repo.
Additional note: the call to GitHub AddCollaborator seems fine.
Proposed solution
Assume that 204 == OK. This seems to be a shortcoming of the GitHub API documentation.
Personally, I'd prefer never erring and only giving warnings. If I have a user that has access to the repo already (say through a team), but we want to give this single user (not the whole team) more access, I'd want to be able to do that through the github_repository_collaborator step. So, if the user already has access to the repo but with LESS permissions than the Terraform is trying to add, then the permissions should update to reflect Terraform.
I also have this issue with repo collaborators that are managed by Terraform via this provider.
Applying the plan creates the collaborators on the repo but then causes the errors noted in this issue.
If you then import the resource into the state and rerun the plan the infra is up to date and not changes are detected.
Hopefully this gets fixed soon.
Hello @anGie44 can we release the 2.9.3 version with this bugfix before 3.0.0?
Thanks in advance
Reacted by André Wendt, Fionn Masuhr, Preston Marshall, Paul Salaberria, Nick Laferriere, Andy, Andrés (Andrew) Amado, Ciaran Moran, Camilo Roca and Brian A. Teller
Activity
anGie44 commentedon May 23, 2020
hi @tpatzig, thank you for writing up this issue!
so I'm able to reproduce this with the latest release of the provider (and not in 2.7.0 as suggested) but only if the collaborator in question is also the owner/admin in the repository being created. what's the relationship of the collaborator to the repository in your case?
jcudit commentedon May 30, 2020
Experimentation confirms identical API calls between the two versions.
More 👀 welcome though in case I missed something:
v2.8.0
v2.7.0
jcudit commentedon May 30, 2020
Looks like we released a change in how we interpret a
204response. I'm unsure of how to proceed as this is in line with GitHub documentation.@tpatzig from a user perspective, would you rather we emit a warning in this scenario instead of failing the run with an error?
HorizonNet commentedon May 31, 2020
@jcudit I ran into the same problem under different circumstances over in #480 and I would rather expect a warning than an error. In my case the user was an organizational admin and got admin permissions automatically for the repository (check via the
/repos/:owner/:repo/collaborators/:username/permissionendpoint). For documentation purposes the admin was also explicitly added to the repositories collaborators where he is an active member.tpatzig commentedon Jun 2, 2020
Hi @anGie44, the collaborator I'm trying to add is an outside the organization collaborator.
It is not the same admin user I've configured the provider with and the repo is created with.
Hi @jcudit, I do not see, why this should fail or error at all 🤷♂️
This outside collaborator is added to that repo for the first time; it is not the owner/admin of that repo. Without that collaborator resource that user would have no permissions on that repo.
anGie44 commentedon Jun 2, 2020
@tpatzig by
outsidedoes that also mean the user is not part of a team within the org and the org hasBase Permissionsset toNone? I was also able to reproduce this scenario inv2.8.0and notv2.7.0by adding a completely new userfoobar(outside org and not the user authenticated with the provider) first to a team that lives within an org (org hasBase Permissionsset toNoneso private repos are not visible from the new user's perspective even while in the team), and then I attempted to add the new user as a collaborator and got the errorError: User foobar is already a collaboratorinv2.8.0HorizonNet commentedon Jun 2, 2020
I also did some more testing on this one today. My organization also has
Base Permissionsset toNoneand I'm trying to add a user (which is already part of my organization) to a repository withWritepermissions. The user gets added, but the apply fails with the error message above. Note that the user is not an organizational administrator.tpatzig commentedon Jun 5, 2020
Yes, with outside collaborator I mean a gh user, that is not part of the organisation (nor in any of the organisations teams) by intention. The
Base Permissionsof our Org isRead.greg-szabo commentedon Jun 14, 2020
Edit: If you want the short version, @jcudit wrote it up here. My take is that the GitHub API documentation is incomplete and 204 should be accepted as an
OKuntil it's fixed/updated. (Which means a manual check needs to happen before the collaborator is added.)I was able to reproduce the issue with
Terraform 0.12.26
provider.github v2.8.1
Test
Result
Additional test
Additional Result
My understanding is that GitHub reports back with a 204 to every command and that is considered an error in Terraform: https://github.com/terraform-providers/terraform-provider-github/blob/master/github/resource_github_repository_collaborator.go#L77
I think GitHub never really had any internal errors about the request, it's just that 204 is the default response to any changes.
Troubleshooting details
According to the GitHub API description on adding collaborators, there are two possible responses to the call:
What the API documentation fails to mention (at least in my case), is that if a user is a member of my organization, the user will not need an invitation to be added as a collaborator to a repository within the organization.
So, my assumption is that since the user doesn't need an invite, a 201 response would be inappropriate. The only other defined response is 204 and for whatever reason, GitHub API chooses to send that in each
OKcase. This suspicion is further advanced by the "Remove a repository collaborator" documentation below in the API, which also responds with 204 if the collaborator was successfully removed.In short: the GitHub API documentation fails to mention that 204 is reported in any regular case.
What's worse, it seems to execute the request properly, before reporting 204, even when the user is really a collaborator on the repo.
Additional note: the call to GitHub AddCollaborator seems fine.
Proposed solution
Assume that 204 ==
OK. This seems to be a shortcoming of the GitHub API documentation.emmahsax commentedon Jun 18, 2020
Personally, I'd prefer never erring and only giving warnings. If I have a user that has access to the repo already (say through a team), but we want to give this single user (not the whole team) more access, I'd want to be able to do that through the
github_repository_collaboratorstep. So, if the user already has access to the repo but with LESS permissions than the Terraform is trying to add, then the permissions should update to reflect Terraform.devinrsmith commentedon Jul 14, 2020
I'm running into this issue now on provider v2.19.
dennasolon commentedon Jul 14, 2020
I also have this issue with repo collaborators that are managed by Terraform via this provider.
Applying the plan creates the collaborators on the repo but then causes the errors noted in this issue.
If you then import the resource into the state and rerun the plan the infra is up to date and not changes are detected.
Hopefully this gets fixed soon.
victorwongth commentedon Aug 14, 2020
Even though this is now closed with a fix, we are still experiencing the issue with
Terraform version v0.12.25
Provider version 2.9.2
We have to revert to Provider version 2.7.0 to get rid of the error.
anGie44 commentedon Aug 14, 2020
Hi @victor-wong-dragon, apologies for the confusion! the PR #525, while merged, hasn't released with a recent version of the provider. I just updated the PR with the
3.0.0milestone link. There are still a couple items in https://github.com/terraform-providers/terraform-provider-github/milestone/12 that are pending before the major release.carbohydrates commentedon Aug 21, 2020
Hello @anGie44 can we release the 2.9.3 version with this bugfix before 3.0.0?
Thanks in advance