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

Supports managing a team's LDAP DN in GitHub Enterprise #39

Merged
merged 1 commit into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
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
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
```
```