Skip to content

Commit

Permalink
Merge pull request #39 from alindeman/team-ldap
Browse files Browse the repository at this point in the history
Supports managing a team's LDAP DN in GitHub Enterprise
  • Loading branch information
grubernaut authored Jul 10, 2017
2 parents 8aaa39a + 77e9153 commit 29b41de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func resourceGithubTeam() *schema.Resource {
Default: "secret",
ValidateFunc: validateValueFunc([]string{"secret", "closed"}),
},
"ldap_dn": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand All @@ -50,6 +54,17 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}

if ldapDN := d.Get("ldap_dn").(string); ldapDN != "" {
mapping := &github.TeamLDAPMapping{
LDAPDN: github.String(ldapDN),
}
_, _, err = client.Admin.UpdateTeamLDAPMapping(context.TODO(), *githubTeam.ID, mapping)
if err != nil {
return err
}
}

d.SetId(fromGithubID(githubTeam.ID))
return resourceGithubTeamRead(d, meta)
}
Expand All @@ -65,6 +80,7 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
d.Set("description", team.Description)
d.Set("name", team.Name)
d.Set("privacy", team.Privacy)
d.Set("ldap_dn", team.GetLDAPDN())
return nil
}

Expand All @@ -88,6 +104,18 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}

if d.HasChange("ldap_dn") {
ldapDN := d.Get("ldap_dn").(string)
mapping := &github.TeamLDAPMapping{
LDAPDN: github.String(ldapDN),
}
_, _, err = client.Admin.UpdateTeamLDAPMapping(context.TODO(), *team.ID, mapping)
if err != nil {
return err
}
}

d.SetId(fromGithubID(team.ID))
return resourceGithubTeamRead(d, meta)
}
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/team.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The following arguments are supported:
* `description` - (Optional) A description of the team.
* `privacy` - (Optional) The level of privacy for the team. Must be one of `secret` or `closed`.
Defaults to `secret`.
* `ldan_dn` - (Optional) The LDAP Distinguished Name of the group where membership will be synchronized. Only available in GitHub Enterprise.

## Attributes Reference

Expand All @@ -45,4 +46,4 @@ Github Teams can be imported using the github team Id e.g.

```
$ terraform import github_team.core 1234567
```
```

0 comments on commit 29b41de

Please sign in to comment.