diff --git a/docs/resources/user.md b/docs/resources/user.md index 9b9f9d8b..5ec936fc 100644 --- a/docs/resources/user.md +++ b/docs/resources/user.md @@ -32,7 +32,7 @@ resource "netbox_user" "test" { ### Optional - `active` (Boolean) Defaults to `true`. -- `groups` (Set of Number) +- `group_ids` (Set of Number) - `staff` (Boolean) Defaults to `false`. ### Read-Only diff --git a/netbox/resource_netbox_user.go b/netbox/resource_netbox_user.go index 42988964..622d22fd 100644 --- a/netbox/resource_netbox_user.go +++ b/netbox/resource_netbox_user.go @@ -38,7 +38,7 @@ func resourceNetboxUser() *schema.Resource { Optional: true, Default: false, }, - "groups": { + "group_ids": { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{ @@ -59,13 +59,13 @@ func resourceNetboxUserCreate(d *schema.ResourceData, m interface{}) error { password := d.Get("password").(string) active := d.Get("active").(bool) staff := d.Get("staff").(bool) - groups := toInt64List(d.Get("groups")) + groupIDs := toInt64List(d.Get("group_ids")) data.Username = &username data.Password = &password data.IsActive = active data.IsStaff = staff - data.Groups = groups + data.Groups = groupIDs params := users.NewUsersUsersCreateParams().WithData(&data) res, err := api.Users.UsersUsersCreate(params, nil) @@ -101,7 +101,7 @@ func resourceNetboxUserRead(d *schema.ResourceData, m interface{}) error { d.Set("staff", res.GetPayload().IsStaff) d.Set("active", res.GetPayload().IsActive) - d.Set("groups", getIDsFromNestedGroup(res.GetPayload().Groups)) + d.Set("group_ids", getIDsFromNestedGroup(res.GetPayload().Groups)) // Passwords cannot be set and not read @@ -117,13 +117,13 @@ func resourceNetboxUserUpdate(d *schema.ResourceData, m interface{}) error { password := d.Get("password").(string) active := d.Get("active").(bool) staff := d.Get("staff").(bool) - groups := toInt64List(d.Get("groups")) + groupIDs := toInt64List(d.Get("group_ids")) data.Username = &username data.Password = &password data.IsActive = active data.IsStaff = staff - data.Groups = groups + data.Groups = groupIDs params := users.NewUsersUsersUpdateParams().WithID(id).WithData(&data) _, err := api.Users.UsersUsersUpdate(params, nil) @@ -152,9 +152,9 @@ func resourceNetboxUserDelete(d *schema.ResourceData, m interface{}) error { } func getIDsFromNestedGroup(nestedGroups []*models.NestedGroup) []int64 { - var groups []int64 + var groupIDs []int64 for _, group := range nestedGroups { - groups = append(groups, group.ID) + groupIDs = append(groupIDs, group.ID) } - return groups + return groupIDs } diff --git a/netbox/resource_netbox_user_test.go b/netbox/resource_netbox_user_test.go index 5141ddfc..34efe95a 100644 --- a/netbox/resource_netbox_user_test.go +++ b/netbox/resource_netbox_user_test.go @@ -59,13 +59,13 @@ resource "netbox_user" "test_group" { password = "abcdefghijkl" active = true staff = true - groups = [netbox_group.test_group.id] + group_ids = [netbox_group.test_group.id] }`, testName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("netbox_user.test_group", "username", testName), resource.TestCheckResourceAttr("netbox_user.test_group", "active", "true"), resource.TestCheckResourceAttr("netbox_user.test_group", "staff", "true"), - resource.TestCheckResourceAttr("netbox_user.test_group", "groups.#", "1"), + resource.TestCheckResourceAttr("netbox_user.test_group", "group_ids.#", "1"), ), }, {