Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let team membership DELETE succeed when user is already removed #1002

Closed
sugitak opened this issue Dec 5, 2021 · 2 comments
Closed

Let team membership DELETE succeed when user is already removed #1002

sugitak opened this issue Dec 5, 2021 · 2 comments
Labels

Comments

@sugitak
Copy link

sugitak commented Dec 5, 2021

Hi, I'm thinking of creating a PR, but before that maybe I should make a discussion on the issue beforehand to check if this change could be accepted on this project or not.

I'm using this module for user management on my GitHub Organization. Also, I'm using a custom module to manage team membership. When I delete a module-capsuled user, as I cannot control the deletion order, terraform-provider-github first deletes the Organization membership of the user. After that it tries to delete the Team membership, but as there's no such user, it fails. Once it fails, there's no other ways to return to normal but to edit the tfstate file.

So I'd like to make this terraform-provider-github module to be able to delete the team membership state when the user is already removed. Does this behavior seem reasonable?

What to be fixed

_, err = client.Teams.RemoveTeamMembershipByID(ctx, orgId, teamId, username)

Here, all the errors are to be thrown again.
I'd like to inspect the error, and if the error is because of the user vacancy, ignore it.

Terraform Version

v0.13.7
(sorry I'm using an old version but I believe it has nothing to do with this issue)

Affected Resource(s)

  • resource_github_team_membership

Terraform Configuration Files

provider "github" {
  token = var.github_token
  organization = var.github_organization
}

resource "github_membership" "sugitak" {
  username = "sugitak"
  role = "member"
}

resource "github_team_membership" "sugitak" {
  team_id = "xxxxxxxx"
  username = "sugitak"
  role = "member"
}

You can create the resources. However, when you try to remove both the membership / team membership at once, membership DELETE will succeed but team membership DELETE may fail. Once it fails, it will never be able to DELETE, and need to edit tfstate file.

Expected Behavior

github_team_membership DELETE to succeed, even if the user is not in the Organization

Actual Behavior

github_team_membership DELETE fails, because the user is not in the team any more

@jcudit jcudit added Type: Feature New feature or request r/team_membership labels Jan 5, 2022
@jcudit
Copy link
Contributor

jcudit commented Jan 5, 2022

#975 introduces another way to manage team membership and may accomplish what you are writing in about for the github_team_membership resource.

I'm also 👍🏾 on your proposed change and can help get a PR merged if desired. Thanks for getting this raised!

@sugitak
Copy link
Author

sugitak commented Apr 12, 2022

Thank you for the response.
After having your comment, I found that in the latest Terraform version (1.1.8) this problem does not occur any more.
So I guess I should be closing this issue.

Thank you again for taking time for this!

@sugitak sugitak closed this as completed Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants