Skip to content

Commit

Permalink
fix: Replace deprecated functions with context aware functions
Browse files Browse the repository at this point in the history
  • Loading branch information
amhn committed Sep 4, 2022
1 parent 80da35b commit f8460bf
Show file tree
Hide file tree
Showing 118 changed files with 1,066 additions and 856 deletions.
13 changes: 7 additions & 6 deletions netbox/data_netbox_dcim_platform.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package netbox

import (
"fmt"
"context"
"regexp"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
netboxclient "github.com/smutel/go-netbox/netbox/client"
Expand All @@ -14,7 +15,7 @@ import (
func dataNetboxDcimPlatform() *schema.Resource {
return &schema.Resource{
Description: "Get info about platform (dcim module) from netbox.",
Read: dataNetboxDcimPlatformRead,
ReadContext: dataNetboxDcimPlatformRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand All @@ -34,7 +35,7 @@ func dataNetboxDcimPlatform() *schema.Resource {
}
}

func dataNetboxDcimPlatformRead(d *schema.ResourceData, m interface{}) error {
func dataNetboxDcimPlatformRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

slug := d.Get("slug").(string)
Expand All @@ -43,14 +44,14 @@ func dataNetboxDcimPlatformRead(d *schema.ResourceData, m interface{}) error {

list, err := client.Dcim.DcimPlatformsList(resource, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
13 changes: 7 additions & 6 deletions netbox/data_netbox_dcim_site.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package netbox

import (
"fmt"
"context"
"regexp"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
netboxclient "github.com/smutel/go-netbox/netbox/client"
Expand All @@ -14,7 +15,7 @@ import (
func dataNetboxDcimSite() *schema.Resource {
return &schema.Resource{
Description: "Get info about site (dcim module) from netbox.",
Read: dataNetboxDcimSiteRead,
ReadContext: dataNetboxDcimSiteRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand All @@ -34,7 +35,7 @@ func dataNetboxDcimSite() *schema.Resource {
}
}

func dataNetboxDcimSiteRead(d *schema.ResourceData, m interface{}) error {
func dataNetboxDcimSiteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

slug := d.Get("slug").(string)
Expand All @@ -43,14 +44,14 @@ func dataNetboxDcimSiteRead(d *schema.ResourceData, m interface{}) error {

list, err := client.Dcim.DcimSitesList(p, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
15 changes: 8 additions & 7 deletions netbox/data_netbox_ipam_aggregate.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package netbox

import (
"fmt"
"context"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
netboxclient "github.com/smutel/go-netbox/netbox/client"
Expand All @@ -13,7 +14,7 @@ import (
func dataNetboxIpamAggregate() *schema.Resource {
return &schema.Resource{
Description: "Get info about aggregate (ipam module) from Netbox.",
Read: dataNetboxIpamAggregateRead,
ReadContext: dataNetboxIpamAggregateRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand All @@ -36,8 +37,8 @@ func dataNetboxIpamAggregate() *schema.Resource {
}
}

func dataNetboxIpamAggregateRead(d *schema.ResourceData,
m interface{}) error {
func dataNetboxIpamAggregateRead(ctx context.Context, d *schema.ResourceData,
m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

prefix := d.Get("prefix").(string)
Expand All @@ -47,14 +48,14 @@ func dataNetboxIpamAggregateRead(d *schema.ResourceData,

list, err := client.Ipam.IpamAggregatesList(p, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
15 changes: 8 additions & 7 deletions netbox/data_netbox_ipam_ip_addresses.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package netbox

import (
"fmt"
"context"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
netboxclient "github.com/smutel/go-netbox/netbox/client"
Expand All @@ -13,7 +14,7 @@ import (
func dataNetboxIpamIPAddresses() *schema.Resource {
return &schema.Resource{
Description: "Get info about IP addresses (ipam module) from netbox.",
Read: dataNetboxIpamIPAddressesRead,
ReadContext: dataNetboxIpamIPAddressesRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand All @@ -31,8 +32,8 @@ func dataNetboxIpamIPAddresses() *schema.Resource {
}
}

func dataNetboxIpamIPAddressesRead(d *schema.ResourceData,
m interface{}) error {
func dataNetboxIpamIPAddressesRead(ctx context.Context, d *schema.ResourceData,
m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

address := d.Get("address").(string)
Expand All @@ -41,14 +42,14 @@ func dataNetboxIpamIPAddressesRead(d *schema.ResourceData,

list, err := client.Ipam.IpamIPAddressesList(p, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
13 changes: 7 additions & 6 deletions netbox/data_netbox_ipam_role.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package netbox

import (
"fmt"
"context"
"regexp"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
netboxclient "github.com/smutel/go-netbox/netbox/client"
Expand All @@ -14,7 +15,7 @@ import (
func dataNetboxIpamRole() *schema.Resource {
return &schema.Resource{
Description: "Get info about role (ipam module) from netbox.",
Read: dataNetboxIpamRoleRead,
ReadContext: dataNetboxIpamRoleRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand All @@ -34,7 +35,7 @@ func dataNetboxIpamRole() *schema.Resource {
}
}

func dataNetboxIpamRoleRead(d *schema.ResourceData, m interface{}) error {
func dataNetboxIpamRoleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

slug := d.Get("slug").(string)
Expand All @@ -43,14 +44,14 @@ func dataNetboxIpamRoleRead(d *schema.ResourceData, m interface{}) error {

list, err := client.Ipam.IpamRolesList(p, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
15 changes: 8 additions & 7 deletions netbox/data_netbox_ipam_service.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package netbox

import (
"fmt"
"context"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
netboxclient "github.com/smutel/go-netbox/netbox/client"
Expand All @@ -13,7 +14,7 @@ import (
func dataNetboxIpamService() *schema.Resource {
return &schema.Resource{
Description: "Get info about a service (ipam module) from netbox.",
Read: dataNetboxIpamServiceRead,
ReadContext: dataNetboxIpamServiceRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand Down Expand Up @@ -55,8 +56,8 @@ func dataNetboxIpamService() *schema.Resource {
}
}

func dataNetboxIpamServiceRead(d *schema.ResourceData,
m interface{}) error {
func dataNetboxIpamServiceRead(ctx context.Context, d *schema.ResourceData,
m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

deviceID := int64(d.Get("device_id").(int))
Expand All @@ -78,14 +79,14 @@ func dataNetboxIpamServiceRead(d *schema.ResourceData,

list, err := client.Ipam.IpamServicesList(p, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
13 changes: 7 additions & 6 deletions netbox/data_netbox_ipam_vlan.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package netbox

import (
"fmt"
"context"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
netboxclient "github.com/smutel/go-netbox/netbox/client"
"github.com/smutel/go-netbox/netbox/client/ipam"
Expand All @@ -12,7 +13,7 @@ import (
func dataNetboxIpamVlan() *schema.Resource {
return &schema.Resource{
Description: "Get info about vlan (ipam module) from netbox.",
Read: dataNetboxIpamVlanRead,
ReadContext: dataNetboxIpamVlanRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand All @@ -34,7 +35,7 @@ func dataNetboxIpamVlan() *schema.Resource {
}
}

func dataNetboxIpamVlanRead(d *schema.ResourceData, m interface{}) error {
func dataNetboxIpamVlanRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

id := int64(d.Get("vlan_id").(int))
Expand All @@ -49,14 +50,14 @@ func dataNetboxIpamVlanRead(d *schema.ResourceData, m interface{}) error {

list, err := client.Ipam.IpamVlansList(p, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
13 changes: 7 additions & 6 deletions netbox/data_netbox_ipam_vlan_group.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package netbox

import (
"fmt"
"context"
"regexp"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
netboxclient "github.com/smutel/go-netbox/netbox/client"
Expand All @@ -14,7 +15,7 @@ import (
func dataNetboxIpamVlanGroup() *schema.Resource {
return &schema.Resource{
Description: "Get info about a vlan group (ipam module) from netbox.",
Read: dataNetboxIpamVlanGroupRead,
ReadContext: dataNetboxIpamVlanGroupRead,

Schema: map[string]*schema.Schema{
"content_type": {
Expand All @@ -34,7 +35,7 @@ func dataNetboxIpamVlanGroup() *schema.Resource {
}
}

func dataNetboxIpamVlanGroupRead(d *schema.ResourceData, m interface{}) error {
func dataNetboxIpamVlanGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*netboxclient.NetBoxAPI)

slug := d.Get("slug").(string)
Expand All @@ -43,14 +44,14 @@ func dataNetboxIpamVlanGroupRead(d *schema.ResourceData, m interface{}) error {

list, err := client.Ipam.IpamVlanGroupsList(p, nil)
if err != nil {
return err
return diag.FromErr(err)
}

if *list.Payload.Count < 1 {
return fmt.Errorf("Your query returned no results. " +
return diag.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
} else if *list.Payload.Count > 1 {
return fmt.Errorf("Your query returned more than one result. " +
return diag.Errorf("Your query returned more than one result. " +
"Please try a more specific search criteria.")
}

Expand Down
Loading

0 comments on commit f8460bf

Please sign in to comment.