Skip to content

Commit da572ed

Browse files
committed
fix(teams): omit group_id from Create/Update payload when empty
Only set GroupID in the API request when non-empty, consistent with how description is handled. Sending an empty string pointer serializes as "group_id": "" in the JSON payload which may cause unexpected API behavior. Omitting the field (nil pointer with omitempty) is the correct way to create a team without a group assignment. Closes #56
1 parent 8cf0acf commit da572ed

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

github/resource_github_enterprise_team.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ func resourceGithubEnterpriseTeamCreate(ctx context.Context, d *schema.ResourceD
8888
req := github.EnterpriseTeamCreateOrUpdateRequest{
8989
Name: name,
9090
OrganizationSelectionType: github.Ptr(orgSelection),
91-
GroupID: github.Ptr(groupID), // Empty string is valid for no group
9291
}
9392
if description != "" {
9493
req.Description = github.Ptr(description)
9594
}
95+
if groupID != "" {
96+
req.GroupID = github.Ptr(groupID)
97+
}
9698

9799
ctx = context.WithValue(ctx, ctxId, d.Id())
98100
te, _, err := client.Enterprise.CreateTeam(ctx, enterpriseSlug, req)
@@ -210,11 +212,13 @@ func resourceGithubEnterpriseTeamUpdate(ctx context.Context, d *schema.ResourceD
210212
req := github.EnterpriseTeamCreateOrUpdateRequest{
211213
Name: name,
212214
OrganizationSelectionType: github.Ptr(orgSelection),
213-
GroupID: github.Ptr(groupID), // Empty string clears the group
214215
}
215216
if description != "" {
216217
req.Description = github.Ptr(description)
217218
}
219+
if groupID != "" {
220+
req.GroupID = github.Ptr(groupID)
221+
}
218222

219223
ctx = context.WithValue(ctx, ctxId, d.Id())
220224
te, _, err := client.Enterprise.UpdateTeam(ctx, enterpriseSlug, teamSlug, req)

0 commit comments

Comments
 (0)