Skip to content

Commit

Permalink
Merge pull request #73 from Ouest-France/managedBy
Browse files Browse the repository at this point in the history
add managedBy attribute support
  • Loading branch information
pablo-ruth authored Sep 16, 2022
2 parents 181a990 + 83b071e commit b6de6a1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ data "ldap_group" "group" {
* `group_type` - Type of the group
* `id` - The DN of the LDAP group.
* `members` - LDAP group members.
* `managed_by` - ManagedBy attribute.
1 change: 1 addition & 0 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ resource "ldap_group" "group" {
* `members` - (Optional) LDAP group members. Defaults to `[]`.
* `description` - (Optional) Description attribute for the LDAP group. Defaults to empty.
* `group_type` - (Optional, Computed) Type of the group.
* `managed_by` - (Optional) ManagedBy attribute. Defaults to ``.

## Attribute Reference

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Ouest-France/terraform-provider-ldap
go 1.18

require (
github.com/Ouest-France/goldap v0.6.1
github.com/Ouest-France/goldap v0.6.2
github.com/go-ldap/ldap/v3 v3.4.4
github.com/hashicorp/terraform-plugin-sdk/v2 v2.23.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e h1:NeAW1fUYUEWhft7pkxDf6WoUvEZJ/uOKsvtpjLnn8MU=
github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Ouest-France/goldap v0.6.1 h1:qMLkRd/CT69rTnP+izTWHyv6z9gJd/IOhXQCh2J5kkw=
github.com/Ouest-France/goldap v0.6.1/go.mod h1:HekerH+zN6sfJbhlK7UvWMSLP4lOtccjCDOofKahT5A=
github.com/Ouest-France/goldap v0.6.2 h1:8uTl/RSbTf/yjHRyhrSRHARSXgaqXqGZmTnB5EODAa8=
github.com/Ouest-France/goldap v0.6.2/go.mod h1:1oPqn1er8HgJglFFCRpY+puY6mnSJQYVxb77wMuCxAA=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down
5 changes: 5 additions & 0 deletions ldap/data_source_resource_ldap_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func dataSourceLDAPGroup() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"managed_by": {
Description: "ManagedBy attribute",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
21 changes: 20 additions & 1 deletion ldap/resource_ldap_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func resourceLDAPGroup() *schema.Resource {
Optional: true,
Computed: true,
},
"managed_by": {
Description: "ManagedBy attribute",
Type: schema.TypeString,
Optional: true,
Default: "",
},
},
}
}
Expand All @@ -74,7 +80,7 @@ func resourceLDAPGroupCreate(ctx context.Context, d *schema.ResourceData, m inte
members = append(members, member.(string))
}

err := client.CreateGroup(dn, d.Get("name").(string), d.Get("description").(string), d.Get("group_type").(string), members)
err := client.CreateGroup(dn, d.Get("name").(string), d.Get("description").(string), d.Get("group_type").(string), d.Get("managed_by").(string), members)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -143,6 +149,13 @@ func resourceLDAPGroupRead(ctx context.Context, d *schema.ResourceData, m interf
if err := d.Set("group_type", groupType); err != nil {
return diag.FromErr(err)
}
managedBy := ""
if val, ok := attributes["managedBy"]; ok {
managedBy = val[0]
}
if err := d.Set("managed_by", managedBy); err != nil {
return diag.FromErr(err)
}

members := []string{}
for name, values := range attributes {
Expand Down Expand Up @@ -183,6 +196,12 @@ func resourceLDAPGroupUpdate(ctx context.Context, d *schema.ResourceData, m inte
}
}

if d.HasChange("managed_by") {
if err := client.UpdateGroupManagedBy(dn, d.Get("managed_by").(string)); err != nil {
return diag.FromErr(err)
}
}

return resourceLDAPGroupRead(ctx, d, m)
}

Expand Down

0 comments on commit b6de6a1

Please sign in to comment.