Skip to content

Commit

Permalink
rename 'groups' field to 'group_ids' in 'netbox_user' resource
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultbustarret-ovhcloud authored and fbreckle committed May 7, 2024
1 parent 8c0ae3f commit 8918469
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions netbox/resource_netbox_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func resourceNetboxUser() *schema.Resource {
Optional: true,
Default: false,
},
"groups": {
"group_ids": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions netbox/resource_netbox_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down

0 comments on commit 8918469

Please sign in to comment.