Skip to content

Commit

Permalink
feat: add limit parameter to interfaces datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
fbreckle committed Mar 11, 2024
1 parent c07d525 commit db5e09a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.8.4 (March 8th, 2024)

ENHANCEMENTS

* data-source/netbox_interfaces: Add `limit` attribute

## 3.8.3 (March 8th, 2024)

ENHANCEMENTS
Expand Down
9 changes: 9 additions & 0 deletions netbox/data_source_netbox_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func dataSourceNetboxInterfaces() *schema.Resource {
},
},
},
"limit": {
Type: schema.TypeInt,
Optional: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)),
Default: 0,
Description: "The limit of objects to return from the API lookup.",
},
"name_regex": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -140,6 +147,8 @@ func dataSourceNetboxInterfaceRead(d *schema.ResourceData, m interface{}) error

params := virtualization.NewVirtualizationInterfacesListParams()

params.Limit = getOptionalInt(d, "limit")

if filter, ok := d.GetOk("filter"); ok {
var filterParams = filter.(*schema.Set)
for _, f := range filterParams.List() {
Expand Down
20 changes: 17 additions & 3 deletions netbox/data_source_netbox_interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func TestAccNetboxInterfacesDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(testResource, "interfaces.1.vm_id", "netbox_virtual_machine.test1", "id"),
),
},
{
Config: dependencies + testAccNetboxInterfacesDataSourceFilterVMWithLimit,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResource, "interfaces.#", "1"),
),
},
{
Config: dependencies + testAccNetboxInterfacesDataSourceNameRegex,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -81,9 +87,7 @@ resource "netbox_interface" "vm1_1" {
resource "netbox_interface" "vm1_2" {
name = "%[1]s_2_regex"
virtual_machine_id = netbox_virtual_machine.test1.id
}
`, testName)
}`, testName)
}

const testAccNetboxInterfacesDataSourceFilterVM = `
Expand All @@ -94,6 +98,16 @@ data "netbox_interfaces" "test" {
}
}`

const testAccNetboxInterfacesDataSourceFilterVMWithLimit = `
data "netbox_interfaces" "test" {
limit = 1
filter {
name = "vm_id"
value = netbox_virtual_machine.test1.id
}
}`

func testAccNetboxInterfacesDataSourceFilterName(testName string) string {
return fmt.Sprintf(`
data "netbox_interfaces" "test" {
Expand Down
12 changes: 6 additions & 6 deletions netbox/resource_netbox_vpn_tunnel_termination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ func init() {
return err
}
for _, vpnTunnelTermination := range res.GetPayload().Results {
deleteParams := vpn.NewVpnTunnelTerminationsDeleteParams().WithID(vpnTunnelTermination.ID)
_, err := api.Vpn.VpnTunnelTerminationsDelete(deleteParams, nil)
if err != nil {
return err
}
log.Print("[DEBUG] Deleted a vpn tunnel termination")
deleteParams := vpn.NewVpnTunnelTerminationsDeleteParams().WithID(vpnTunnelTermination.ID)
_, err := api.Vpn.VpnTunnelTerminationsDelete(deleteParams, nil)
if err != nil {
return err
}
log.Print("[DEBUG] Deleted a vpn tunnel termination")
}
return nil
},
Expand Down

0 comments on commit db5e09a

Please sign in to comment.