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

The create API can also be used to modify the role #1276

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions github/resource_github_team_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func resourceGithubTeamMembersUpdate(d *schema.ResourceData, meta interface{}) e
}

for username, change := range vals {
var create, delete bool
var create, delete, update bool

switch {
// create a new one if old is nil
Expand All @@ -132,13 +132,12 @@ func resourceGithubTeamMembersUpdate(d *schema.ResourceData, meta interface{}) e
// delete existing if new is nil
case change.New == nil:
delete = true
// no change
// no change
case reflect.DeepEqual(change.Old, change.New):
continue
// recreate - role changed
// update - role changed
default:
delete = true
create = true
update = true
}

if delete {
Expand Down Expand Up @@ -166,6 +165,24 @@ func resourceGithubTeamMembersUpdate(d *schema.ResourceData, meta interface{}) e
return err
}
}

if update {
role := change.New["role"].(string)
from := change.Old["role"].(string)

log.Printf("[DEBUG] Updating team membership: %s/%s (%s -> %s)", teamIdString, username, from, role)
_, _, err = client.Teams.AddTeamMembershipByID(ctx,
orgId,
teamId,
username,
&github.TeamAddTeamMembershipOptions{
Role: role,
},
)
if err != nil {
return err
}
}
}

d.SetId(teamIdString)
Expand Down