Skip to content

Commit

Permalink
Update descriptions for user and group datasources. (#69)
Browse files Browse the repository at this point in the history
Also rename the ID fields for group and user datasources to something more meaningful.
  • Loading branch information
koikonom authored Jan 7, 2021
1 parent 90c3d53 commit abc7485
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
13 changes: 7 additions & 6 deletions ad/data_source_ad_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func dataSourceADGroup() *schema.Resource {
Description: "Get the details of an Active Directory Group object.",
Read: dataSourceADGroupRead,
Schema: map[string]*schema.Schema{
"guid": {
"group_id": {
Type: schema.TypeString,
Required: true,
Description: "The GUID of the Group object.",
Description: "The group's identifier. It can be the group's GUID, SID, Distinguished Name, or SAM Account Name.",
},
"sam_account_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -59,22 +59,23 @@ func dataSourceADGroupRead(d *schema.ResourceData, meta interface{}) error {
}
defer meta.(ProviderConf).ReleaseWinRMClient(client)

dn := d.Get("guid").(string)
groupID := d.Get("group_id").(string)

g, err := winrmhelper.GetGroupFromHost(client, dn)
g, err := winrmhelper.GetGroupFromHost(client, groupID)
if err != nil {
return err
}
if g == nil {
return fmt.Errorf("No group found with dn %q", dn)
return fmt.Errorf("No group found with group_id %q", groupID)
}
_ = d.Set("sam_account_name", g.SAMAccountName)
_ = d.Set("display_name", g.Name)
_ = d.Set("scope", g.Scope)
_ = d.Set("category", g.Category)
_ = d.Set("container", g.Container)
_ = d.Set("name", g.Name)
_ = d.Set("group_id", groupID)

d.SetId(dn)
d.SetId(g.GUID)
return nil
}
2 changes: 1 addition & 1 deletion ad/data_source_ad_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func testAccDatasourceADGroupConfigBasic(domain, name, sam, scope, gtype string)
}
data "ad_group" "d" {
guid = ad_group.g.id
group_id = ad_group.g.id
}
`, name, sam, scope, gtype)
}
12 changes: 6 additions & 6 deletions ad/data_source_ad_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func dataSourceADUser() *schema.Resource {
Description: "Get the details of an Active Directory user object.",
Read: dataSourceADUserRead,
Schema: map[string]*schema.Schema{
"guid": {
"user_id": {
Type: schema.TypeString,
Required: true,
Description: "The GUID of the user object.",
Description: "The user's identifier. It can be the group's GUID, SID, Distinguished Name, or SAM Account Name.",
},
"sam_account_name": {
Type: schema.TypeString,
Expand All @@ -38,25 +38,25 @@ func dataSourceADUser() *schema.Resource {
}

func dataSourceADUserRead(d *schema.ResourceData, meta interface{}) error {
dn := d.Get("guid").(string)
userID := d.Get("user_id").(string)
client, err := meta.(ProviderConf).AcquireWinRMClient()
if err != nil {
return err
}
defer meta.(ProviderConf).ReleaseWinRMClient(client)

u, err := winrmhelper.GetUserFromHost(client, dn)
u, err := winrmhelper.GetUserFromHost(client, userID)
if err != nil {
return err
}

if u == nil {
return fmt.Errorf("No user found with dn %q", dn)
return fmt.Errorf("No user found with user_id %q", userID)
}
_ = d.Set("sam_account_name", u.SAMAccountName)
_ = d.Set("display_name", u.DisplayName)
_ = d.Set("principal_name", u.PrincipalName)
_ = d.Set("guid", u.GUID)
_ = d.Set("user_id", userID)
d.SetId(u.GUID)

return nil
Expand Down
2 changes: 1 addition & 1 deletion ad/data_source_ad_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func testAccDataSourceADUserBasic(domain, username, password string) string {
}
data "ad_user" "d" {
guid = ad_user.a.id
user_id = ad_user.a.id
}
`, principalName, password, username)
}
2 changes: 1 addition & 1 deletion docs/data-sources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ output "groupname" {

### Required

- **guid** (String, Required) The GUID of the Group object.
- **group_id** (String, Required) The group's identifier. It can be the group's GUID, SID, Distinguished Name, or SAM Account Name.

### Optional

Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ output "username" {

### Required

- **guid** (String, Required) The GUID of the user object.
- **user_id** (String, Required) The user's identifier. It can be the group's GUID, SID, Distinguished Name, or SAM Account Name.

### Optional

Expand Down

0 comments on commit abc7485

Please sign in to comment.