diff --git a/CHANGELOG.md b/CHANGELOG.md index ec4e17b6..701c0200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/netbox/data_source_netbox_interfaces.go b/netbox/data_source_netbox_interfaces.go index fb94f579..b2e0e6c0 100644 --- a/netbox/data_source_netbox_interfaces.go +++ b/netbox/data_source_netbox_interfaces.go @@ -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, @@ -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() { diff --git a/netbox/data_source_netbox_interfaces_test.go b/netbox/data_source_netbox_interfaces_test.go index 4c30eb93..e8c5eb15 100644 --- a/netbox/data_source_netbox_interfaces_test.go +++ b/netbox/data_source_netbox_interfaces_test.go @@ -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( @@ -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 = ` @@ -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" { diff --git a/netbox/resource_netbox_vpn_tunnel_termination_test.go b/netbox/resource_netbox_vpn_tunnel_termination_test.go index aec35c70..11582086 100644 --- a/netbox/resource_netbox_vpn_tunnel_termination_test.go +++ b/netbox/resource_netbox_vpn_tunnel_termination_test.go @@ -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 },