From d421340320c4c2fd12b670a829f19c8240a3a7ae Mon Sep 17 00:00:00 2001 From: "J. Mark Pim" Date: Tue, 17 Jan 2023 17:45:22 +0000 Subject: [PATCH 1/2] Set LDAP DN on team creation fixes #1490 Set `LDAPDN` on the `NewTeam` on creation, if it's not the empty string. This avoids an extra call to the GHE API, but more importantly means the user does not need to be a site admin to create a team with LDAP sync --- github/resource_github_team.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/github/resource_github_team.go b/github/resource_github_team.go index 45d5f061f3..d926943c91 100644 --- a/github/resource_github_team.go +++ b/github/resource_github_team.go @@ -92,6 +92,10 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error { Description: github.String(d.Get("description").(string)), Privacy: github.String(d.Get("privacy").(string)), } + + if ldapDN := d.Get("ldap_dn").(string); ldapDN != "" { + newTeam.LDAPDN = &ldapDN + } if parentTeamID, ok := d.GetOk("parent_team_id"); ok { id := int64(parentTeamID.(int)) @@ -138,16 +142,6 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error { } } - if ldapDN := d.Get("ldap_dn").(string); ldapDN != "" { - mapping := &github.TeamLDAPMapping{ - LDAPDN: github.String(ldapDN), - } - _, _, err = client.Admin.UpdateTeamLDAPMapping(ctx, githubTeam.GetID(), mapping) - if err != nil { - return err - } - } - d.SetId(strconv.FormatInt(githubTeam.GetID(), 10)) return resourceGithubTeamRead(d, meta) } From 9451e7d94f2015cda0ee9aba0a9cd9a6469c534f Mon Sep 17 00:00:00 2001 From: "J. Mark Pim" Date: Wed, 18 Jan 2023 10:03:40 +0000 Subject: [PATCH 2/2] Fix linting? --- github/resource_github_team.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/resource_github_team.go b/github/resource_github_team.go index d926943c91..63616a4918 100644 --- a/github/resource_github_team.go +++ b/github/resource_github_team.go @@ -92,9 +92,9 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error { Description: github.String(d.Get("description").(string)), Privacy: github.String(d.Get("privacy").(string)), } - + if ldapDN := d.Get("ldap_dn").(string); ldapDN != "" { - newTeam.LDAPDN = &ldapDN + newTeam.LDAPDN = &ldapDN } if parentTeamID, ok := d.GetOk("parent_team_id"); ok {