From f8460bfaf38e1dae5a8efedfee553e6120aa041b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Nie=C3=9F?= Date: Sun, 4 Sep 2022 15:57:28 +0200 Subject: [PATCH] fix: Replace deprecated functions with context aware functions --- netbox/data_netbox_dcim_platform.go | 13 ++- netbox/data_netbox_dcim_site.go | 13 ++- netbox/data_netbox_ipam_aggregate.go | 15 +-- netbox/data_netbox_ipam_ip_addresses.go | 15 +-- netbox/data_netbox_ipam_role.go | 13 ++- netbox/data_netbox_ipam_service.go | 15 +-- netbox/data_netbox_ipam_vlan.go | 13 ++- netbox/data_netbox_ipam_vlan_group.go | 13 ++- ...json_circuits_circuit_terminations_list.go | 8 +- ...netbox_json_circuits_circuit_types_list.go | 8 +- ...data_netbox_json_circuits_circuits_list.go | 8 +- ...ox_json_circuits_provider_networks_list.go | 8 +- ...ata_netbox_json_circuits_providers_list.go | 8 +- netbox/data_netbox_json_dcim_cables_list.go | 8 +- ...x_json_dcim_console_port_templates_list.go | 8 +- ...ata_netbox_json_dcim_console_ports_list.go | 8 +- ...dcim_console_server_port_templates_list.go | 8 +- ...box_json_dcim_console_server_ports_list.go | 8 +- ...box_json_dcim_device_bay_templates_list.go | 8 +- .../data_netbox_json_dcim_device_bays_list.go | 8 +- ...data_netbox_json_dcim_device_roles_list.go | 8 +- ...data_netbox_json_dcim_device_types_list.go | 8 +- netbox/data_netbox_json_dcim_devices_list.go | 8 +- ...box_json_dcim_front_port_templates_list.go | 8 +- .../data_netbox_json_dcim_front_ports_list.go | 8 +- ...tbox_json_dcim_interface_templates_list.go | 8 +- .../data_netbox_json_dcim_interfaces_list.go | 8 +- ...box_json_dcim_inventory_item_roles_list.go | 8 +- ...json_dcim_inventory_item_templates_list.go | 8 +- ...a_netbox_json_dcim_inventory_items_list.go | 8 +- .../data_netbox_json_dcim_locations_list.go | 8 +- ...ata_netbox_json_dcim_manufacturers_list.go | 8 +- ...box_json_dcim_module_bay_templates_list.go | 8 +- .../data_netbox_json_dcim_module_bays_list.go | 8 +- ...data_netbox_json_dcim_module_types_list.go | 8 +- netbox/data_netbox_json_dcim_modules_list.go | 8 +- .../data_netbox_json_dcim_platforms_list.go | 8 +- .../data_netbox_json_dcim_power_feeds_list.go | 8 +- ...x_json_dcim_power_outlet_templates_list.go | 8 +- ...ata_netbox_json_dcim_power_outlets_list.go | 8 +- ...data_netbox_json_dcim_power_panels_list.go | 8 +- ...box_json_dcim_power_port_templates_list.go | 8 +- .../data_netbox_json_dcim_power_ports_list.go | 8 +- ...netbox_json_dcim_rack_reservations_list.go | 8 +- .../data_netbox_json_dcim_rack_roles_list.go | 8 +- netbox/data_netbox_json_dcim_racks_list.go | 8 +- ...tbox_json_dcim_rear_port_templates_list.go | 8 +- .../data_netbox_json_dcim_rear_ports_list.go | 8 +- netbox/data_netbox_json_dcim_regions_list.go | 8 +- .../data_netbox_json_dcim_site_groups_list.go | 8 +- netbox/data_netbox_json_dcim_sites_list.go | 8 +- ...a_netbox_json_dcim_virtual_chassis_list.go | 8 +- ...netbox_json_extras_config_contexts_list.go | 8 +- ...a_netbox_json_extras_content_types_list.go | 8 +- ...a_netbox_json_extras_custom_fields_list.go | 8 +- ...ta_netbox_json_extras_custom_links_list.go | 8 +- ...etbox_json_extras_export_templates_list.go | 8 +- ...tbox_json_extras_image_attachments_list.go | 8 +- ...ata_netbox_json_extras_job_results_list.go | 8 +- ...netbox_json_extras_journal_entries_list.go | 8 +- ..._netbox_json_extras_object_changes_list.go | 8 +- netbox/data_netbox_json_extras_tags_list.go | 8 +- .../data_netbox_json_extras_webhooks_list.go | 8 +- .../data_netbox_json_ipam_aggregates_list.go | 8 +- netbox/data_netbox_json_ipam_asns_list.go | 8 +- ...x_json_ipam_fhrp_group_assignments_list.go | 8 +- .../data_netbox_json_ipam_fhrp_groups_list.go | 8 +- ...data_netbox_json_ipam_ip_addresses_list.go | 8 +- .../data_netbox_json_ipam_ip_ranges_list.go | 8 +- netbox/data_netbox_json_ipam_prefixes_list.go | 8 +- netbox/data_netbox_json_ipam_rirs_list.go | 8 +- netbox/data_netbox_json_ipam_roles_list.go | 8 +- ...ata_netbox_json_ipam_route_targets_list.go | 8 +- ...netbox_json_ipam_service_templates_list.go | 8 +- netbox/data_netbox_json_ipam_services_list.go | 8 +- .../data_netbox_json_ipam_vlan_groups_list.go | 8 +- netbox/data_netbox_json_ipam_vlans_list.go | 8 +- netbox/data_netbox_json_ipam_vrfs_list.go | 8 +- ...x_json_tenancy_contact_assignments_list.go | 8 +- ...netbox_json_tenancy_contact_groups_list.go | 8 +- ..._netbox_json_tenancy_contact_roles_list.go | 8 +- .../data_netbox_json_tenancy_contacts_list.go | 8 +- ..._netbox_json_tenancy_tenant_groups_list.go | 8 +- .../data_netbox_json_tenancy_tenants_list.go | 8 +- netbox/data_netbox_json_users_groups_list.go | 8 +- ...data_netbox_json_users_permissions_list.go | 8 +- netbox/data_netbox_json_users_tokens_list.go | 8 +- netbox/data_netbox_json_users_users_list.go | 8 +- ...json_virtualization_cluster_groups_list.go | 8 +- ..._json_virtualization_cluster_types_list.go | 8 +- ...etbox_json_virtualization_clusters_list.go | 8 +- ...box_json_virtualization_interfaces_list.go | 8 +- ...on_virtualization_virtual_machines_list.go | 8 +- ..._json_wireless_wireless_lan_groups_list.go | 8 +- ...netbox_json_wireless_wireless_lans_list.go | 8 +- ...etbox_json_wireless_wireless_links_list.go | 8 +- netbox/data_netbox_tenancy_contact.go | 13 ++- netbox/data_netbox_tenancy_contact_group.go | 13 ++- netbox/data_netbox_tenancy_tenant.go | 13 ++- netbox/data_netbox_tenancy_tenant_group.go | 15 +-- netbox/data_netbox_tenancy_tenant_role.go | 15 +-- netbox/data_netbox_virtualization_cluster.go | 15 +-- netbox/provider.go | 6 +- netbox/resource_netbox_ipam_aggregate.go | 68 +++++------ netbox/resource_netbox_ipam_ip_addresses.go | 107 +++++++++--------- netbox/resource_netbox_ipam_prefix.go | 85 +++++++------- netbox/resource_netbox_ipam_service.go | 71 ++++++------ netbox/resource_netbox_ipam_vlan.go | 79 ++++++------- netbox/resource_netbox_ipam_vlan_group.go | 55 ++++----- netbox/resource_netbox_tenancy_contact.go | 70 ++++++------ ...ource_netbox_tenancy_contact_assignment.go | 60 +++++----- .../resource_netbox_tenancy_contact_group.go | 65 +++++------ .../resource_netbox_tenancy_contact_role.go | 61 +++++----- netbox/resource_netbox_tenancy_tenant.go | 67 +++++------ .../resource_netbox_tenancy_tenant_group.go | 57 +++++----- ...esource_netbox_virtualization_interface.go | 79 ++++++------- netbox/resource_netbox_virtualization_vm.go | 88 +++++++------- utils/generateJsonDatasources | 6 +- 118 files changed, 1066 insertions(+), 856 deletions(-) diff --git a/netbox/data_netbox_dcim_platform.go b/netbox/data_netbox_dcim_platform.go index c3e5b8c68..75b3606c8 100644 --- a/netbox/data_netbox_dcim_platform.go +++ b/netbox/data_netbox_dcim_platform.go @@ -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" @@ -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": { @@ -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) @@ -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.") } diff --git a/netbox/data_netbox_dcim_site.go b/netbox/data_netbox_dcim_site.go index 30b2500b7..5eccca304 100644 --- a/netbox/data_netbox_dcim_site.go +++ b/netbox/data_netbox_dcim_site.go @@ -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" @@ -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": { @@ -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) @@ -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.") } diff --git a/netbox/data_netbox_ipam_aggregate.go b/netbox/data_netbox_ipam_aggregate.go index ddd68014c..f6263d30a 100644 --- a/netbox/data_netbox_ipam_aggregate.go +++ b/netbox/data_netbox_ipam_aggregate.go @@ -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" @@ -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": { @@ -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) @@ -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.") } diff --git a/netbox/data_netbox_ipam_ip_addresses.go b/netbox/data_netbox_ipam_ip_addresses.go index 5f93ec395..2159a7abd 100644 --- a/netbox/data_netbox_ipam_ip_addresses.go +++ b/netbox/data_netbox_ipam_ip_addresses.go @@ -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" @@ -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": { @@ -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) @@ -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.") } diff --git a/netbox/data_netbox_ipam_role.go b/netbox/data_netbox_ipam_role.go index e76219c85..159afc702 100644 --- a/netbox/data_netbox_ipam_role.go +++ b/netbox/data_netbox_ipam_role.go @@ -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" @@ -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": { @@ -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) @@ -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.") } diff --git a/netbox/data_netbox_ipam_service.go b/netbox/data_netbox_ipam_service.go index 16343995e..03f0aa4af 100644 --- a/netbox/data_netbox_ipam_service.go +++ b/netbox/data_netbox_ipam_service.go @@ -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" @@ -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": { @@ -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)) @@ -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.") } diff --git a/netbox/data_netbox_ipam_vlan.go b/netbox/data_netbox_ipam_vlan.go index 5497577f0..6481e5c52 100644 --- a/netbox/data_netbox_ipam_vlan.go +++ b/netbox/data_netbox_ipam_vlan.go @@ -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" @@ -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": { @@ -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)) @@ -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.") } diff --git a/netbox/data_netbox_ipam_vlan_group.go b/netbox/data_netbox_ipam_vlan_group.go index f89e959dd..f12eab2b0 100644 --- a/netbox/data_netbox_ipam_vlan_group.go +++ b/netbox/data_netbox_ipam_vlan_group.go @@ -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" @@ -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": { @@ -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) @@ -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.") } diff --git a/netbox/data_netbox_json_circuits_circuit_terminations_list.go b/netbox/data_netbox_json_circuits_circuit_terminations_list.go index 29c866d4d..8a6bb9254 100644 --- a/netbox/data_netbox_json_circuits_circuit_terminations_list.go +++ b/netbox/data_netbox_json_circuits_circuit_terminations_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/circuits" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONCircuitsCircuitTerminationsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the circuits_circuit_terminations_list Netbox endpoint.", - Read: dataNetboxJSONCircuitsCircuitTerminationsListRead, + ReadContext: dataNetboxJSONCircuitsCircuitTerminationsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONCircuitsCircuitTerminationsList() *schema.Resource { } } -func dataNetboxJSONCircuitsCircuitTerminationsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONCircuitsCircuitTerminationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := circuits.NewCircuitsCircuitTerminationsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONCircuitsCircuitTerminationsListRead(d *schema.ResourceData, m list, err := client.Circuits.CircuitsCircuitTerminationsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_circuits_circuit_types_list.go b/netbox/data_netbox_json_circuits_circuit_types_list.go index b30368f73..dae859fa3 100644 --- a/netbox/data_netbox_json_circuits_circuit_types_list.go +++ b/netbox/data_netbox_json_circuits_circuit_types_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/circuits" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONCircuitsCircuitTypesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the circuits_circuit_types_list Netbox endpoint.", - Read: dataNetboxJSONCircuitsCircuitTypesListRead, + ReadContext: dataNetboxJSONCircuitsCircuitTypesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONCircuitsCircuitTypesList() *schema.Resource { } } -func dataNetboxJSONCircuitsCircuitTypesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONCircuitsCircuitTypesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := circuits.NewCircuitsCircuitTypesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONCircuitsCircuitTypesListRead(d *schema.ResourceData, m interf list, err := client.Circuits.CircuitsCircuitTypesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_circuits_circuits_list.go b/netbox/data_netbox_json_circuits_circuits_list.go index 17221113a..6fa77c03e 100644 --- a/netbox/data_netbox_json_circuits_circuits_list.go +++ b/netbox/data_netbox_json_circuits_circuits_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/circuits" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONCircuitsCircuitsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the circuits_circuits_list Netbox endpoint.", - Read: dataNetboxJSONCircuitsCircuitsListRead, + ReadContext: dataNetboxJSONCircuitsCircuitsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONCircuitsCircuitsList() *schema.Resource { } } -func dataNetboxJSONCircuitsCircuitsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONCircuitsCircuitsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := circuits.NewCircuitsCircuitsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONCircuitsCircuitsListRead(d *schema.ResourceData, m interface{ list, err := client.Circuits.CircuitsCircuitsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_circuits_provider_networks_list.go b/netbox/data_netbox_json_circuits_provider_networks_list.go index 2e7bcc261..694f9fb76 100644 --- a/netbox/data_netbox_json_circuits_provider_networks_list.go +++ b/netbox/data_netbox_json_circuits_provider_networks_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/circuits" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONCircuitsProviderNetworksList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the circuits_provider_networks_list Netbox endpoint.", - Read: dataNetboxJSONCircuitsProviderNetworksListRead, + ReadContext: dataNetboxJSONCircuitsProviderNetworksListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONCircuitsProviderNetworksList() *schema.Resource { } } -func dataNetboxJSONCircuitsProviderNetworksListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONCircuitsProviderNetworksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := circuits.NewCircuitsProviderNetworksListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONCircuitsProviderNetworksListRead(d *schema.ResourceData, m in list, err := client.Circuits.CircuitsProviderNetworksList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_circuits_providers_list.go b/netbox/data_netbox_json_circuits_providers_list.go index ab1a58fc2..df39a3102 100644 --- a/netbox/data_netbox_json_circuits_providers_list.go +++ b/netbox/data_netbox_json_circuits_providers_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/circuits" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONCircuitsProvidersList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the circuits_providers_list Netbox endpoint.", - Read: dataNetboxJSONCircuitsProvidersListRead, + ReadContext: dataNetboxJSONCircuitsProvidersListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONCircuitsProvidersList() *schema.Resource { } } -func dataNetboxJSONCircuitsProvidersListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONCircuitsProvidersListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := circuits.NewCircuitsProvidersListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONCircuitsProvidersListRead(d *schema.ResourceData, m interface list, err := client.Circuits.CircuitsProvidersList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_cables_list.go b/netbox/data_netbox_json_dcim_cables_list.go index 0375b7bcc..8b9c5715f 100644 --- a/netbox/data_netbox_json_dcim_cables_list.go +++ b/netbox/data_netbox_json_dcim_cables_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimCablesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_cables_list Netbox endpoint.", - Read: dataNetboxJSONDcimCablesListRead, + ReadContext: dataNetboxJSONDcimCablesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimCablesList() *schema.Resource { } } -func dataNetboxJSONDcimCablesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimCablesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimCablesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimCablesListRead(d *schema.ResourceData, m interface{}) err list, err := client.Dcim.DcimCablesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_console_port_templates_list.go b/netbox/data_netbox_json_dcim_console_port_templates_list.go index 367af3765..ce1880d32 100644 --- a/netbox/data_netbox_json_dcim_console_port_templates_list.go +++ b/netbox/data_netbox_json_dcim_console_port_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimConsolePortTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_console_port_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimConsolePortTemplatesListRead, + ReadContext: dataNetboxJSONDcimConsolePortTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimConsolePortTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimConsolePortTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimConsolePortTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimConsolePortTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimConsolePortTemplatesListRead(d *schema.ResourceData, m in list, err := client.Dcim.DcimConsolePortTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_console_ports_list.go b/netbox/data_netbox_json_dcim_console_ports_list.go index 202339d51..8925280f4 100644 --- a/netbox/data_netbox_json_dcim_console_ports_list.go +++ b/netbox/data_netbox_json_dcim_console_ports_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimConsolePortsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_console_ports_list Netbox endpoint.", - Read: dataNetboxJSONDcimConsolePortsListRead, + ReadContext: dataNetboxJSONDcimConsolePortsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimConsolePortsList() *schema.Resource { } } -func dataNetboxJSONDcimConsolePortsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimConsolePortsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimConsolePortsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimConsolePortsListRead(d *schema.ResourceData, m interface{ list, err := client.Dcim.DcimConsolePortsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_console_server_port_templates_list.go b/netbox/data_netbox_json_dcim_console_server_port_templates_list.go index 5f984c53f..36ca7729e 100644 --- a/netbox/data_netbox_json_dcim_console_server_port_templates_list.go +++ b/netbox/data_netbox_json_dcim_console_server_port_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimConsoleServerPortTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_console_server_port_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimConsoleServerPortTemplatesListRead, + ReadContext: dataNetboxJSONDcimConsoleServerPortTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimConsoleServerPortTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimConsoleServerPortTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimConsoleServerPortTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimConsoleServerPortTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimConsoleServerPortTemplatesListRead(d *schema.ResourceData list, err := client.Dcim.DcimConsoleServerPortTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_console_server_ports_list.go b/netbox/data_netbox_json_dcim_console_server_ports_list.go index d78b353e7..f76a582f8 100644 --- a/netbox/data_netbox_json_dcim_console_server_ports_list.go +++ b/netbox/data_netbox_json_dcim_console_server_ports_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimConsoleServerPortsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_console_server_ports_list Netbox endpoint.", - Read: dataNetboxJSONDcimConsoleServerPortsListRead, + ReadContext: dataNetboxJSONDcimConsoleServerPortsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimConsoleServerPortsList() *schema.Resource { } } -func dataNetboxJSONDcimConsoleServerPortsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimConsoleServerPortsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimConsoleServerPortsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimConsoleServerPortsListRead(d *schema.ResourceData, m inte list, err := client.Dcim.DcimConsoleServerPortsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_device_bay_templates_list.go b/netbox/data_netbox_json_dcim_device_bay_templates_list.go index d8cf1ac77..9f4543d1e 100644 --- a/netbox/data_netbox_json_dcim_device_bay_templates_list.go +++ b/netbox/data_netbox_json_dcim_device_bay_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimDeviceBayTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_device_bay_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimDeviceBayTemplatesListRead, + ReadContext: dataNetboxJSONDcimDeviceBayTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimDeviceBayTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimDeviceBayTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimDeviceBayTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimDeviceBayTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimDeviceBayTemplatesListRead(d *schema.ResourceData, m inte list, err := client.Dcim.DcimDeviceBayTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_device_bays_list.go b/netbox/data_netbox_json_dcim_device_bays_list.go index 297f757f6..73d055a6b 100644 --- a/netbox/data_netbox_json_dcim_device_bays_list.go +++ b/netbox/data_netbox_json_dcim_device_bays_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimDeviceBaysList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_device_bays_list Netbox endpoint.", - Read: dataNetboxJSONDcimDeviceBaysListRead, + ReadContext: dataNetboxJSONDcimDeviceBaysListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimDeviceBaysList() *schema.Resource { } } -func dataNetboxJSONDcimDeviceBaysListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimDeviceBaysListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimDeviceBaysListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimDeviceBaysListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimDeviceBaysList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_device_roles_list.go b/netbox/data_netbox_json_dcim_device_roles_list.go index e4e8d012c..44e4f2a0d 100644 --- a/netbox/data_netbox_json_dcim_device_roles_list.go +++ b/netbox/data_netbox_json_dcim_device_roles_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimDeviceRolesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_device_roles_list Netbox endpoint.", - Read: dataNetboxJSONDcimDeviceRolesListRead, + ReadContext: dataNetboxJSONDcimDeviceRolesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimDeviceRolesList() *schema.Resource { } } -func dataNetboxJSONDcimDeviceRolesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimDeviceRolesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimDeviceRolesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimDeviceRolesListRead(d *schema.ResourceData, m interface{} list, err := client.Dcim.DcimDeviceRolesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_device_types_list.go b/netbox/data_netbox_json_dcim_device_types_list.go index ceeb6b28b..d12b93dc5 100644 --- a/netbox/data_netbox_json_dcim_device_types_list.go +++ b/netbox/data_netbox_json_dcim_device_types_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimDeviceTypesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_device_types_list Netbox endpoint.", - Read: dataNetboxJSONDcimDeviceTypesListRead, + ReadContext: dataNetboxJSONDcimDeviceTypesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimDeviceTypesList() *schema.Resource { } } -func dataNetboxJSONDcimDeviceTypesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimDeviceTypesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimDeviceTypesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimDeviceTypesListRead(d *schema.ResourceData, m interface{} list, err := client.Dcim.DcimDeviceTypesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_devices_list.go b/netbox/data_netbox_json_dcim_devices_list.go index 6d934ab97..51ad6262d 100644 --- a/netbox/data_netbox_json_dcim_devices_list.go +++ b/netbox/data_netbox_json_dcim_devices_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimDevicesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_devices_list Netbox endpoint.", - Read: dataNetboxJSONDcimDevicesListRead, + ReadContext: dataNetboxJSONDcimDevicesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimDevicesList() *schema.Resource { } } -func dataNetboxJSONDcimDevicesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimDevicesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimDevicesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimDevicesListRead(d *schema.ResourceData, m interface{}) er list, err := client.Dcim.DcimDevicesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_front_port_templates_list.go b/netbox/data_netbox_json_dcim_front_port_templates_list.go index d0ff16752..41e53058c 100644 --- a/netbox/data_netbox_json_dcim_front_port_templates_list.go +++ b/netbox/data_netbox_json_dcim_front_port_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimFrontPortTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_front_port_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimFrontPortTemplatesListRead, + ReadContext: dataNetboxJSONDcimFrontPortTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimFrontPortTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimFrontPortTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimFrontPortTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimFrontPortTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimFrontPortTemplatesListRead(d *schema.ResourceData, m inte list, err := client.Dcim.DcimFrontPortTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_front_ports_list.go b/netbox/data_netbox_json_dcim_front_ports_list.go index 3a3dda6e9..6e7945e15 100644 --- a/netbox/data_netbox_json_dcim_front_ports_list.go +++ b/netbox/data_netbox_json_dcim_front_ports_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimFrontPortsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_front_ports_list Netbox endpoint.", - Read: dataNetboxJSONDcimFrontPortsListRead, + ReadContext: dataNetboxJSONDcimFrontPortsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimFrontPortsList() *schema.Resource { } } -func dataNetboxJSONDcimFrontPortsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimFrontPortsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimFrontPortsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimFrontPortsListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimFrontPortsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_interface_templates_list.go b/netbox/data_netbox_json_dcim_interface_templates_list.go index 17184f334..9f6fee24d 100644 --- a/netbox/data_netbox_json_dcim_interface_templates_list.go +++ b/netbox/data_netbox_json_dcim_interface_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimInterfaceTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_interface_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimInterfaceTemplatesListRead, + ReadContext: dataNetboxJSONDcimInterfaceTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimInterfaceTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimInterfaceTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimInterfaceTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimInterfaceTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimInterfaceTemplatesListRead(d *schema.ResourceData, m inte list, err := client.Dcim.DcimInterfaceTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_interfaces_list.go b/netbox/data_netbox_json_dcim_interfaces_list.go index 9a530dd9e..ca40f2413 100644 --- a/netbox/data_netbox_json_dcim_interfaces_list.go +++ b/netbox/data_netbox_json_dcim_interfaces_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimInterfacesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_interfaces_list Netbox endpoint.", - Read: dataNetboxJSONDcimInterfacesListRead, + ReadContext: dataNetboxJSONDcimInterfacesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimInterfacesList() *schema.Resource { } } -func dataNetboxJSONDcimInterfacesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimInterfacesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimInterfacesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimInterfacesListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimInterfacesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_inventory_item_roles_list.go b/netbox/data_netbox_json_dcim_inventory_item_roles_list.go index 353ded35f..5a6a931ed 100644 --- a/netbox/data_netbox_json_dcim_inventory_item_roles_list.go +++ b/netbox/data_netbox_json_dcim_inventory_item_roles_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimInventoryItemRolesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_inventory_item_roles_list Netbox endpoint.", - Read: dataNetboxJSONDcimInventoryItemRolesListRead, + ReadContext: dataNetboxJSONDcimInventoryItemRolesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimInventoryItemRolesList() *schema.Resource { } } -func dataNetboxJSONDcimInventoryItemRolesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimInventoryItemRolesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimInventoryItemRolesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimInventoryItemRolesListRead(d *schema.ResourceData, m inte list, err := client.Dcim.DcimInventoryItemRolesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_inventory_item_templates_list.go b/netbox/data_netbox_json_dcim_inventory_item_templates_list.go index 8ca0495ca..cfaadac6c 100644 --- a/netbox/data_netbox_json_dcim_inventory_item_templates_list.go +++ b/netbox/data_netbox_json_dcim_inventory_item_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimInventoryItemTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_inventory_item_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimInventoryItemTemplatesListRead, + ReadContext: dataNetboxJSONDcimInventoryItemTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimInventoryItemTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimInventoryItemTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimInventoryItemTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimInventoryItemTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimInventoryItemTemplatesListRead(d *schema.ResourceData, m list, err := client.Dcim.DcimInventoryItemTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_inventory_items_list.go b/netbox/data_netbox_json_dcim_inventory_items_list.go index c5580116c..87d399aa0 100644 --- a/netbox/data_netbox_json_dcim_inventory_items_list.go +++ b/netbox/data_netbox_json_dcim_inventory_items_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimInventoryItemsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_inventory_items_list Netbox endpoint.", - Read: dataNetboxJSONDcimInventoryItemsListRead, + ReadContext: dataNetboxJSONDcimInventoryItemsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimInventoryItemsList() *schema.Resource { } } -func dataNetboxJSONDcimInventoryItemsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimInventoryItemsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimInventoryItemsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimInventoryItemsListRead(d *schema.ResourceData, m interfac list, err := client.Dcim.DcimInventoryItemsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_locations_list.go b/netbox/data_netbox_json_dcim_locations_list.go index 64532305e..c346f8202 100644 --- a/netbox/data_netbox_json_dcim_locations_list.go +++ b/netbox/data_netbox_json_dcim_locations_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimLocationsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_locations_list Netbox endpoint.", - Read: dataNetboxJSONDcimLocationsListRead, + ReadContext: dataNetboxJSONDcimLocationsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimLocationsList() *schema.Resource { } } -func dataNetboxJSONDcimLocationsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimLocationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimLocationsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimLocationsListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimLocationsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_manufacturers_list.go b/netbox/data_netbox_json_dcim_manufacturers_list.go index 5a646e0df..65ff5b768 100644 --- a/netbox/data_netbox_json_dcim_manufacturers_list.go +++ b/netbox/data_netbox_json_dcim_manufacturers_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimManufacturersList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_manufacturers_list Netbox endpoint.", - Read: dataNetboxJSONDcimManufacturersListRead, + ReadContext: dataNetboxJSONDcimManufacturersListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimManufacturersList() *schema.Resource { } } -func dataNetboxJSONDcimManufacturersListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimManufacturersListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimManufacturersListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimManufacturersListRead(d *schema.ResourceData, m interface list, err := client.Dcim.DcimManufacturersList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_module_bay_templates_list.go b/netbox/data_netbox_json_dcim_module_bay_templates_list.go index 5219db6b1..32788ce9e 100644 --- a/netbox/data_netbox_json_dcim_module_bay_templates_list.go +++ b/netbox/data_netbox_json_dcim_module_bay_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimModuleBayTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_module_bay_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimModuleBayTemplatesListRead, + ReadContext: dataNetboxJSONDcimModuleBayTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimModuleBayTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimModuleBayTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimModuleBayTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimModuleBayTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimModuleBayTemplatesListRead(d *schema.ResourceData, m inte list, err := client.Dcim.DcimModuleBayTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_module_bays_list.go b/netbox/data_netbox_json_dcim_module_bays_list.go index c21f9870d..15712596d 100644 --- a/netbox/data_netbox_json_dcim_module_bays_list.go +++ b/netbox/data_netbox_json_dcim_module_bays_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimModuleBaysList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_module_bays_list Netbox endpoint.", - Read: dataNetboxJSONDcimModuleBaysListRead, + ReadContext: dataNetboxJSONDcimModuleBaysListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimModuleBaysList() *schema.Resource { } } -func dataNetboxJSONDcimModuleBaysListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimModuleBaysListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimModuleBaysListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimModuleBaysListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimModuleBaysList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_module_types_list.go b/netbox/data_netbox_json_dcim_module_types_list.go index 3bc0c55bf..3f0eab44b 100644 --- a/netbox/data_netbox_json_dcim_module_types_list.go +++ b/netbox/data_netbox_json_dcim_module_types_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimModuleTypesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_module_types_list Netbox endpoint.", - Read: dataNetboxJSONDcimModuleTypesListRead, + ReadContext: dataNetboxJSONDcimModuleTypesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimModuleTypesList() *schema.Resource { } } -func dataNetboxJSONDcimModuleTypesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimModuleTypesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimModuleTypesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimModuleTypesListRead(d *schema.ResourceData, m interface{} list, err := client.Dcim.DcimModuleTypesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_modules_list.go b/netbox/data_netbox_json_dcim_modules_list.go index 37b1b40d2..ec741d012 100644 --- a/netbox/data_netbox_json_dcim_modules_list.go +++ b/netbox/data_netbox_json_dcim_modules_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimModulesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_modules_list Netbox endpoint.", - Read: dataNetboxJSONDcimModulesListRead, + ReadContext: dataNetboxJSONDcimModulesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimModulesList() *schema.Resource { } } -func dataNetboxJSONDcimModulesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimModulesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimModulesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimModulesListRead(d *schema.ResourceData, m interface{}) er list, err := client.Dcim.DcimModulesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_platforms_list.go b/netbox/data_netbox_json_dcim_platforms_list.go index 58f79abe8..a934644b4 100644 --- a/netbox/data_netbox_json_dcim_platforms_list.go +++ b/netbox/data_netbox_json_dcim_platforms_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimPlatformsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_platforms_list Netbox endpoint.", - Read: dataNetboxJSONDcimPlatformsListRead, + ReadContext: dataNetboxJSONDcimPlatformsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimPlatformsList() *schema.Resource { } } -func dataNetboxJSONDcimPlatformsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimPlatformsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimPlatformsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimPlatformsListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimPlatformsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_power_feeds_list.go b/netbox/data_netbox_json_dcim_power_feeds_list.go index 2230f3734..052852fbc 100644 --- a/netbox/data_netbox_json_dcim_power_feeds_list.go +++ b/netbox/data_netbox_json_dcim_power_feeds_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimPowerFeedsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_power_feeds_list Netbox endpoint.", - Read: dataNetboxJSONDcimPowerFeedsListRead, + ReadContext: dataNetboxJSONDcimPowerFeedsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimPowerFeedsList() *schema.Resource { } } -func dataNetboxJSONDcimPowerFeedsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimPowerFeedsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimPowerFeedsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimPowerFeedsListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimPowerFeedsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_power_outlet_templates_list.go b/netbox/data_netbox_json_dcim_power_outlet_templates_list.go index 89af98e89..379570016 100644 --- a/netbox/data_netbox_json_dcim_power_outlet_templates_list.go +++ b/netbox/data_netbox_json_dcim_power_outlet_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimPowerOutletTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_power_outlet_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimPowerOutletTemplatesListRead, + ReadContext: dataNetboxJSONDcimPowerOutletTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimPowerOutletTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimPowerOutletTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimPowerOutletTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimPowerOutletTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimPowerOutletTemplatesListRead(d *schema.ResourceData, m in list, err := client.Dcim.DcimPowerOutletTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_power_outlets_list.go b/netbox/data_netbox_json_dcim_power_outlets_list.go index 3a6db37e0..44cfd3508 100644 --- a/netbox/data_netbox_json_dcim_power_outlets_list.go +++ b/netbox/data_netbox_json_dcim_power_outlets_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimPowerOutletsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_power_outlets_list Netbox endpoint.", - Read: dataNetboxJSONDcimPowerOutletsListRead, + ReadContext: dataNetboxJSONDcimPowerOutletsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimPowerOutletsList() *schema.Resource { } } -func dataNetboxJSONDcimPowerOutletsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimPowerOutletsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimPowerOutletsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimPowerOutletsListRead(d *schema.ResourceData, m interface{ list, err := client.Dcim.DcimPowerOutletsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_power_panels_list.go b/netbox/data_netbox_json_dcim_power_panels_list.go index 98006499b..11000ebb5 100644 --- a/netbox/data_netbox_json_dcim_power_panels_list.go +++ b/netbox/data_netbox_json_dcim_power_panels_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimPowerPanelsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_power_panels_list Netbox endpoint.", - Read: dataNetboxJSONDcimPowerPanelsListRead, + ReadContext: dataNetboxJSONDcimPowerPanelsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimPowerPanelsList() *schema.Resource { } } -func dataNetboxJSONDcimPowerPanelsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimPowerPanelsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimPowerPanelsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimPowerPanelsListRead(d *schema.ResourceData, m interface{} list, err := client.Dcim.DcimPowerPanelsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_power_port_templates_list.go b/netbox/data_netbox_json_dcim_power_port_templates_list.go index ecc38886f..212c16607 100644 --- a/netbox/data_netbox_json_dcim_power_port_templates_list.go +++ b/netbox/data_netbox_json_dcim_power_port_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimPowerPortTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_power_port_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimPowerPortTemplatesListRead, + ReadContext: dataNetboxJSONDcimPowerPortTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimPowerPortTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimPowerPortTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimPowerPortTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimPowerPortTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimPowerPortTemplatesListRead(d *schema.ResourceData, m inte list, err := client.Dcim.DcimPowerPortTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_power_ports_list.go b/netbox/data_netbox_json_dcim_power_ports_list.go index 9783865f8..6b5690fce 100644 --- a/netbox/data_netbox_json_dcim_power_ports_list.go +++ b/netbox/data_netbox_json_dcim_power_ports_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimPowerPortsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_power_ports_list Netbox endpoint.", - Read: dataNetboxJSONDcimPowerPortsListRead, + ReadContext: dataNetboxJSONDcimPowerPortsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimPowerPortsList() *schema.Resource { } } -func dataNetboxJSONDcimPowerPortsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimPowerPortsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimPowerPortsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimPowerPortsListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimPowerPortsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_rack_reservations_list.go b/netbox/data_netbox_json_dcim_rack_reservations_list.go index 2c75ff02a..45726a138 100644 --- a/netbox/data_netbox_json_dcim_rack_reservations_list.go +++ b/netbox/data_netbox_json_dcim_rack_reservations_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimRackReservationsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_rack_reservations_list Netbox endpoint.", - Read: dataNetboxJSONDcimRackReservationsListRead, + ReadContext: dataNetboxJSONDcimRackReservationsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimRackReservationsList() *schema.Resource { } } -func dataNetboxJSONDcimRackReservationsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimRackReservationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimRackReservationsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimRackReservationsListRead(d *schema.ResourceData, m interf list, err := client.Dcim.DcimRackReservationsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_rack_roles_list.go b/netbox/data_netbox_json_dcim_rack_roles_list.go index 843352e3f..9347edf68 100644 --- a/netbox/data_netbox_json_dcim_rack_roles_list.go +++ b/netbox/data_netbox_json_dcim_rack_roles_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimRackRolesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_rack_roles_list Netbox endpoint.", - Read: dataNetboxJSONDcimRackRolesListRead, + ReadContext: dataNetboxJSONDcimRackRolesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimRackRolesList() *schema.Resource { } } -func dataNetboxJSONDcimRackRolesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimRackRolesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimRackRolesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimRackRolesListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimRackRolesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_racks_list.go b/netbox/data_netbox_json_dcim_racks_list.go index ff8509f3b..24a50d825 100644 --- a/netbox/data_netbox_json_dcim_racks_list.go +++ b/netbox/data_netbox_json_dcim_racks_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimRacksList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_racks_list Netbox endpoint.", - Read: dataNetboxJSONDcimRacksListRead, + ReadContext: dataNetboxJSONDcimRacksListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimRacksList() *schema.Resource { } } -func dataNetboxJSONDcimRacksListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimRacksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimRacksListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimRacksListRead(d *schema.ResourceData, m interface{}) erro list, err := client.Dcim.DcimRacksList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_rear_port_templates_list.go b/netbox/data_netbox_json_dcim_rear_port_templates_list.go index 50cc41b42..574508c84 100644 --- a/netbox/data_netbox_json_dcim_rear_port_templates_list.go +++ b/netbox/data_netbox_json_dcim_rear_port_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimRearPortTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_rear_port_templates_list Netbox endpoint.", - Read: dataNetboxJSONDcimRearPortTemplatesListRead, + ReadContext: dataNetboxJSONDcimRearPortTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimRearPortTemplatesList() *schema.Resource { } } -func dataNetboxJSONDcimRearPortTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimRearPortTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimRearPortTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimRearPortTemplatesListRead(d *schema.ResourceData, m inter list, err := client.Dcim.DcimRearPortTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_rear_ports_list.go b/netbox/data_netbox_json_dcim_rear_ports_list.go index 5025f76c2..4621ced6e 100644 --- a/netbox/data_netbox_json_dcim_rear_ports_list.go +++ b/netbox/data_netbox_json_dcim_rear_ports_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimRearPortsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_rear_ports_list Netbox endpoint.", - Read: dataNetboxJSONDcimRearPortsListRead, + ReadContext: dataNetboxJSONDcimRearPortsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimRearPortsList() *schema.Resource { } } -func dataNetboxJSONDcimRearPortsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimRearPortsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimRearPortsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimRearPortsListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimRearPortsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_regions_list.go b/netbox/data_netbox_json_dcim_regions_list.go index ebbc71497..90388ccda 100644 --- a/netbox/data_netbox_json_dcim_regions_list.go +++ b/netbox/data_netbox_json_dcim_regions_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimRegionsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_regions_list Netbox endpoint.", - Read: dataNetboxJSONDcimRegionsListRead, + ReadContext: dataNetboxJSONDcimRegionsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimRegionsList() *schema.Resource { } } -func dataNetboxJSONDcimRegionsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimRegionsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimRegionsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimRegionsListRead(d *schema.ResourceData, m interface{}) er list, err := client.Dcim.DcimRegionsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_site_groups_list.go b/netbox/data_netbox_json_dcim_site_groups_list.go index 0881af47d..af9980938 100644 --- a/netbox/data_netbox_json_dcim_site_groups_list.go +++ b/netbox/data_netbox_json_dcim_site_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimSiteGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_site_groups_list Netbox endpoint.", - Read: dataNetboxJSONDcimSiteGroupsListRead, + ReadContext: dataNetboxJSONDcimSiteGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimSiteGroupsList() *schema.Resource { } } -func dataNetboxJSONDcimSiteGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimSiteGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimSiteGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimSiteGroupsListRead(d *schema.ResourceData, m interface{}) list, err := client.Dcim.DcimSiteGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_sites_list.go b/netbox/data_netbox_json_dcim_sites_list.go index f3981b54f..629043014 100644 --- a/netbox/data_netbox_json_dcim_sites_list.go +++ b/netbox/data_netbox_json_dcim_sites_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimSitesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_sites_list Netbox endpoint.", - Read: dataNetboxJSONDcimSitesListRead, + ReadContext: dataNetboxJSONDcimSitesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimSitesList() *schema.Resource { } } -func dataNetboxJSONDcimSitesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimSitesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimSitesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimSitesListRead(d *schema.ResourceData, m interface{}) erro list, err := client.Dcim.DcimSitesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_dcim_virtual_chassis_list.go b/netbox/data_netbox_json_dcim_virtual_chassis_list.go index d4a818814..8908bc341 100644 --- a/netbox/data_netbox_json_dcim_virtual_chassis_list.go +++ b/netbox/data_netbox_json_dcim_virtual_chassis_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/dcim" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONDcimVirtualChassisList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the dcim_virtual_chassis_list Netbox endpoint.", - Read: dataNetboxJSONDcimVirtualChassisListRead, + ReadContext: dataNetboxJSONDcimVirtualChassisListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONDcimVirtualChassisList() *schema.Resource { } } -func dataNetboxJSONDcimVirtualChassisListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONDcimVirtualChassisListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := dcim.NewDcimVirtualChassisListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONDcimVirtualChassisListRead(d *schema.ResourceData, m interfac list, err := client.Dcim.DcimVirtualChassisList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_config_contexts_list.go b/netbox/data_netbox_json_extras_config_contexts_list.go index 512c4d2c2..f3cac717c 100644 --- a/netbox/data_netbox_json_extras_config_contexts_list.go +++ b/netbox/data_netbox_json_extras_config_contexts_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasConfigContextsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_config_contexts_list Netbox endpoint.", - Read: dataNetboxJSONExtrasConfigContextsListRead, + ReadContext: dataNetboxJSONExtrasConfigContextsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasConfigContextsList() *schema.Resource { } } -func dataNetboxJSONExtrasConfigContextsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasConfigContextsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasConfigContextsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasConfigContextsListRead(d *schema.ResourceData, m interf list, err := client.Extras.ExtrasConfigContextsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_content_types_list.go b/netbox/data_netbox_json_extras_content_types_list.go index 254592930..8567aac23 100644 --- a/netbox/data_netbox_json_extras_content_types_list.go +++ b/netbox/data_netbox_json_extras_content_types_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasContentTypesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_content_types_list Netbox endpoint.", - Read: dataNetboxJSONExtrasContentTypesListRead, + ReadContext: dataNetboxJSONExtrasContentTypesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasContentTypesList() *schema.Resource { } } -func dataNetboxJSONExtrasContentTypesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasContentTypesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasContentTypesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasContentTypesListRead(d *schema.ResourceData, m interfac list, err := client.Extras.ExtrasContentTypesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_custom_fields_list.go b/netbox/data_netbox_json_extras_custom_fields_list.go index 6cd0dd5a0..4a07e33f7 100644 --- a/netbox/data_netbox_json_extras_custom_fields_list.go +++ b/netbox/data_netbox_json_extras_custom_fields_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasCustomFieldsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_custom_fields_list Netbox endpoint.", - Read: dataNetboxJSONExtrasCustomFieldsListRead, + ReadContext: dataNetboxJSONExtrasCustomFieldsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasCustomFieldsList() *schema.Resource { } } -func dataNetboxJSONExtrasCustomFieldsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasCustomFieldsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasCustomFieldsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasCustomFieldsListRead(d *schema.ResourceData, m interfac list, err := client.Extras.ExtrasCustomFieldsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_custom_links_list.go b/netbox/data_netbox_json_extras_custom_links_list.go index 14052b2b4..c6f8e42a7 100644 --- a/netbox/data_netbox_json_extras_custom_links_list.go +++ b/netbox/data_netbox_json_extras_custom_links_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasCustomLinksList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_custom_links_list Netbox endpoint.", - Read: dataNetboxJSONExtrasCustomLinksListRead, + ReadContext: dataNetboxJSONExtrasCustomLinksListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasCustomLinksList() *schema.Resource { } } -func dataNetboxJSONExtrasCustomLinksListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasCustomLinksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasCustomLinksListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasCustomLinksListRead(d *schema.ResourceData, m interface list, err := client.Extras.ExtrasCustomLinksList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_export_templates_list.go b/netbox/data_netbox_json_extras_export_templates_list.go index 8df8af45c..c476d5313 100644 --- a/netbox/data_netbox_json_extras_export_templates_list.go +++ b/netbox/data_netbox_json_extras_export_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasExportTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_export_templates_list Netbox endpoint.", - Read: dataNetboxJSONExtrasExportTemplatesListRead, + ReadContext: dataNetboxJSONExtrasExportTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasExportTemplatesList() *schema.Resource { } } -func dataNetboxJSONExtrasExportTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasExportTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasExportTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasExportTemplatesListRead(d *schema.ResourceData, m inter list, err := client.Extras.ExtrasExportTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_image_attachments_list.go b/netbox/data_netbox_json_extras_image_attachments_list.go index d8f29fc3b..3cf71f94d 100644 --- a/netbox/data_netbox_json_extras_image_attachments_list.go +++ b/netbox/data_netbox_json_extras_image_attachments_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasImageAttachmentsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_image_attachments_list Netbox endpoint.", - Read: dataNetboxJSONExtrasImageAttachmentsListRead, + ReadContext: dataNetboxJSONExtrasImageAttachmentsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasImageAttachmentsList() *schema.Resource { } } -func dataNetboxJSONExtrasImageAttachmentsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasImageAttachmentsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasImageAttachmentsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasImageAttachmentsListRead(d *schema.ResourceData, m inte list, err := client.Extras.ExtrasImageAttachmentsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_job_results_list.go b/netbox/data_netbox_json_extras_job_results_list.go index 5aa32f696..38c7175ae 100644 --- a/netbox/data_netbox_json_extras_job_results_list.go +++ b/netbox/data_netbox_json_extras_job_results_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasJobResultsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_job_results_list Netbox endpoint.", - Read: dataNetboxJSONExtrasJobResultsListRead, + ReadContext: dataNetboxJSONExtrasJobResultsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasJobResultsList() *schema.Resource { } } -func dataNetboxJSONExtrasJobResultsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasJobResultsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasJobResultsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasJobResultsListRead(d *schema.ResourceData, m interface{ list, err := client.Extras.ExtrasJobResultsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_journal_entries_list.go b/netbox/data_netbox_json_extras_journal_entries_list.go index 67d4250be..a4158acee 100644 --- a/netbox/data_netbox_json_extras_journal_entries_list.go +++ b/netbox/data_netbox_json_extras_journal_entries_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasJournalEntriesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_journal_entries_list Netbox endpoint.", - Read: dataNetboxJSONExtrasJournalEntriesListRead, + ReadContext: dataNetboxJSONExtrasJournalEntriesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasJournalEntriesList() *schema.Resource { } } -func dataNetboxJSONExtrasJournalEntriesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasJournalEntriesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasJournalEntriesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasJournalEntriesListRead(d *schema.ResourceData, m interf list, err := client.Extras.ExtrasJournalEntriesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_object_changes_list.go b/netbox/data_netbox_json_extras_object_changes_list.go index 51d023336..fd866c4b7 100644 --- a/netbox/data_netbox_json_extras_object_changes_list.go +++ b/netbox/data_netbox_json_extras_object_changes_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasObjectChangesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_object_changes_list Netbox endpoint.", - Read: dataNetboxJSONExtrasObjectChangesListRead, + ReadContext: dataNetboxJSONExtrasObjectChangesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasObjectChangesList() *schema.Resource { } } -func dataNetboxJSONExtrasObjectChangesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasObjectChangesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasObjectChangesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasObjectChangesListRead(d *schema.ResourceData, m interfa list, err := client.Extras.ExtrasObjectChangesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_tags_list.go b/netbox/data_netbox_json_extras_tags_list.go index b308b8b97..18c9302cc 100644 --- a/netbox/data_netbox_json_extras_tags_list.go +++ b/netbox/data_netbox_json_extras_tags_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasTagsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_tags_list Netbox endpoint.", - Read: dataNetboxJSONExtrasTagsListRead, + ReadContext: dataNetboxJSONExtrasTagsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasTagsList() *schema.Resource { } } -func dataNetboxJSONExtrasTagsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasTagsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasTagsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasTagsListRead(d *schema.ResourceData, m interface{}) err list, err := client.Extras.ExtrasTagsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_extras_webhooks_list.go b/netbox/data_netbox_json_extras_webhooks_list.go index b1889f374..3c4fd3bd7 100644 --- a/netbox/data_netbox_json_extras_webhooks_list.go +++ b/netbox/data_netbox_json_extras_webhooks_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/extras" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONExtrasWebhooksList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the extras_webhooks_list Netbox endpoint.", - Read: dataNetboxJSONExtrasWebhooksListRead, + ReadContext: dataNetboxJSONExtrasWebhooksListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONExtrasWebhooksList() *schema.Resource { } } -func dataNetboxJSONExtrasWebhooksListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONExtrasWebhooksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := extras.NewExtrasWebhooksListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONExtrasWebhooksListRead(d *schema.ResourceData, m interface{}) list, err := client.Extras.ExtrasWebhooksList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_aggregates_list.go b/netbox/data_netbox_json_ipam_aggregates_list.go index c2f422a53..049f3c653 100644 --- a/netbox/data_netbox_json_ipam_aggregates_list.go +++ b/netbox/data_netbox_json_ipam_aggregates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamAggregatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_aggregates_list Netbox endpoint.", - Read: dataNetboxJSONIpamAggregatesListRead, + ReadContext: dataNetboxJSONIpamAggregatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamAggregatesList() *schema.Resource { } } -func dataNetboxJSONIpamAggregatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamAggregatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamAggregatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamAggregatesListRead(d *schema.ResourceData, m interface{}) list, err := client.Ipam.IpamAggregatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_asns_list.go b/netbox/data_netbox_json_ipam_asns_list.go index 276c9fa41..a3083a1a4 100644 --- a/netbox/data_netbox_json_ipam_asns_list.go +++ b/netbox/data_netbox_json_ipam_asns_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamAsnsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_asns_list Netbox endpoint.", - Read: dataNetboxJSONIpamAsnsListRead, + ReadContext: dataNetboxJSONIpamAsnsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamAsnsList() *schema.Resource { } } -func dataNetboxJSONIpamAsnsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamAsnsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamAsnsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamAsnsListRead(d *schema.ResourceData, m interface{}) error list, err := client.Ipam.IpamAsnsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_fhrp_group_assignments_list.go b/netbox/data_netbox_json_ipam_fhrp_group_assignments_list.go index 32ded73ff..4b2690264 100644 --- a/netbox/data_netbox_json_ipam_fhrp_group_assignments_list.go +++ b/netbox/data_netbox_json_ipam_fhrp_group_assignments_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamFhrpGroupAssignmentsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_fhrp_group_assignments_list Netbox endpoint.", - Read: dataNetboxJSONIpamFhrpGroupAssignmentsListRead, + ReadContext: dataNetboxJSONIpamFhrpGroupAssignmentsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamFhrpGroupAssignmentsList() *schema.Resource { } } -func dataNetboxJSONIpamFhrpGroupAssignmentsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamFhrpGroupAssignmentsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamFhrpGroupAssignmentsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamFhrpGroupAssignmentsListRead(d *schema.ResourceData, m in list, err := client.Ipam.IpamFhrpGroupAssignmentsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_fhrp_groups_list.go b/netbox/data_netbox_json_ipam_fhrp_groups_list.go index 1c1b8f260..ff24be6ed 100644 --- a/netbox/data_netbox_json_ipam_fhrp_groups_list.go +++ b/netbox/data_netbox_json_ipam_fhrp_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamFhrpGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_fhrp_groups_list Netbox endpoint.", - Read: dataNetboxJSONIpamFhrpGroupsListRead, + ReadContext: dataNetboxJSONIpamFhrpGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamFhrpGroupsList() *schema.Resource { } } -func dataNetboxJSONIpamFhrpGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamFhrpGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamFhrpGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamFhrpGroupsListRead(d *schema.ResourceData, m interface{}) list, err := client.Ipam.IpamFhrpGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_ip_addresses_list.go b/netbox/data_netbox_json_ipam_ip_addresses_list.go index d08383b8d..d3dd3f54f 100644 --- a/netbox/data_netbox_json_ipam_ip_addresses_list.go +++ b/netbox/data_netbox_json_ipam_ip_addresses_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamIPAddressesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_ip_addresses_list Netbox endpoint.", - Read: dataNetboxJSONIpamIPAddressesListRead, + ReadContext: dataNetboxJSONIpamIPAddressesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamIPAddressesList() *schema.Resource { } } -func dataNetboxJSONIpamIPAddressesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamIPAddressesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamIPAddressesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamIPAddressesListRead(d *schema.ResourceData, m interface{} list, err := client.Ipam.IpamIPAddressesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_ip_ranges_list.go b/netbox/data_netbox_json_ipam_ip_ranges_list.go index c1ec2d447..642f67cb4 100644 --- a/netbox/data_netbox_json_ipam_ip_ranges_list.go +++ b/netbox/data_netbox_json_ipam_ip_ranges_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamIPRangesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_ip_ranges_list Netbox endpoint.", - Read: dataNetboxJSONIpamIPRangesListRead, + ReadContext: dataNetboxJSONIpamIPRangesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamIPRangesList() *schema.Resource { } } -func dataNetboxJSONIpamIPRangesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamIPRangesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamIPRangesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamIPRangesListRead(d *schema.ResourceData, m interface{}) e list, err := client.Ipam.IpamIPRangesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_prefixes_list.go b/netbox/data_netbox_json_ipam_prefixes_list.go index 8a1b90903..a53ea583d 100644 --- a/netbox/data_netbox_json_ipam_prefixes_list.go +++ b/netbox/data_netbox_json_ipam_prefixes_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamPrefixesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_prefixes_list Netbox endpoint.", - Read: dataNetboxJSONIpamPrefixesListRead, + ReadContext: dataNetboxJSONIpamPrefixesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamPrefixesList() *schema.Resource { } } -func dataNetboxJSONIpamPrefixesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamPrefixesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamPrefixesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamPrefixesListRead(d *schema.ResourceData, m interface{}) e list, err := client.Ipam.IpamPrefixesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_rirs_list.go b/netbox/data_netbox_json_ipam_rirs_list.go index 366594962..a86d43811 100644 --- a/netbox/data_netbox_json_ipam_rirs_list.go +++ b/netbox/data_netbox_json_ipam_rirs_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamRirsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_rirs_list Netbox endpoint.", - Read: dataNetboxJSONIpamRirsListRead, + ReadContext: dataNetboxJSONIpamRirsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamRirsList() *schema.Resource { } } -func dataNetboxJSONIpamRirsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamRirsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamRirsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamRirsListRead(d *schema.ResourceData, m interface{}) error list, err := client.Ipam.IpamRirsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_roles_list.go b/netbox/data_netbox_json_ipam_roles_list.go index fe88fbd4f..b9fe17cfd 100644 --- a/netbox/data_netbox_json_ipam_roles_list.go +++ b/netbox/data_netbox_json_ipam_roles_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamRolesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_roles_list Netbox endpoint.", - Read: dataNetboxJSONIpamRolesListRead, + ReadContext: dataNetboxJSONIpamRolesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamRolesList() *schema.Resource { } } -func dataNetboxJSONIpamRolesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamRolesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamRolesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamRolesListRead(d *schema.ResourceData, m interface{}) erro list, err := client.Ipam.IpamRolesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_route_targets_list.go b/netbox/data_netbox_json_ipam_route_targets_list.go index 8250965ac..d5fc86356 100644 --- a/netbox/data_netbox_json_ipam_route_targets_list.go +++ b/netbox/data_netbox_json_ipam_route_targets_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamRouteTargetsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_route_targets_list Netbox endpoint.", - Read: dataNetboxJSONIpamRouteTargetsListRead, + ReadContext: dataNetboxJSONIpamRouteTargetsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamRouteTargetsList() *schema.Resource { } } -func dataNetboxJSONIpamRouteTargetsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamRouteTargetsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamRouteTargetsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamRouteTargetsListRead(d *schema.ResourceData, m interface{ list, err := client.Ipam.IpamRouteTargetsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_service_templates_list.go b/netbox/data_netbox_json_ipam_service_templates_list.go index 0c6cd649b..4248c61d6 100644 --- a/netbox/data_netbox_json_ipam_service_templates_list.go +++ b/netbox/data_netbox_json_ipam_service_templates_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamServiceTemplatesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_service_templates_list Netbox endpoint.", - Read: dataNetboxJSONIpamServiceTemplatesListRead, + ReadContext: dataNetboxJSONIpamServiceTemplatesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamServiceTemplatesList() *schema.Resource { } } -func dataNetboxJSONIpamServiceTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamServiceTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamServiceTemplatesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamServiceTemplatesListRead(d *schema.ResourceData, m interf list, err := client.Ipam.IpamServiceTemplatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_services_list.go b/netbox/data_netbox_json_ipam_services_list.go index a6690f492..7ba6b94ef 100644 --- a/netbox/data_netbox_json_ipam_services_list.go +++ b/netbox/data_netbox_json_ipam_services_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamServicesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_services_list Netbox endpoint.", - Read: dataNetboxJSONIpamServicesListRead, + ReadContext: dataNetboxJSONIpamServicesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamServicesList() *schema.Resource { } } -func dataNetboxJSONIpamServicesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamServicesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamServicesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamServicesListRead(d *schema.ResourceData, m interface{}) e list, err := client.Ipam.IpamServicesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_vlan_groups_list.go b/netbox/data_netbox_json_ipam_vlan_groups_list.go index 5e6518be8..0dd6bcb8d 100644 --- a/netbox/data_netbox_json_ipam_vlan_groups_list.go +++ b/netbox/data_netbox_json_ipam_vlan_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamVlanGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_vlan_groups_list Netbox endpoint.", - Read: dataNetboxJSONIpamVlanGroupsListRead, + ReadContext: dataNetboxJSONIpamVlanGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamVlanGroupsList() *schema.Resource { } } -func dataNetboxJSONIpamVlanGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamVlanGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamVlanGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamVlanGroupsListRead(d *schema.ResourceData, m interface{}) list, err := client.Ipam.IpamVlanGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_vlans_list.go b/netbox/data_netbox_json_ipam_vlans_list.go index 64264086d..086bba159 100644 --- a/netbox/data_netbox_json_ipam_vlans_list.go +++ b/netbox/data_netbox_json_ipam_vlans_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamVlansList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_vlans_list Netbox endpoint.", - Read: dataNetboxJSONIpamVlansListRead, + ReadContext: dataNetboxJSONIpamVlansListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamVlansList() *schema.Resource { } } -func dataNetboxJSONIpamVlansListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamVlansListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamVlansListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamVlansListRead(d *schema.ResourceData, m interface{}) erro list, err := client.Ipam.IpamVlansList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_ipam_vrfs_list.go b/netbox/data_netbox_json_ipam_vrfs_list.go index 025204ce4..f5ee912d8 100644 --- a/netbox/data_netbox_json_ipam_vrfs_list.go +++ b/netbox/data_netbox_json_ipam_vrfs_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONIpamVrfsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ipam_vrfs_list Netbox endpoint.", - Read: dataNetboxJSONIpamVrfsListRead, + ReadContext: dataNetboxJSONIpamVrfsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONIpamVrfsList() *schema.Resource { } } -func dataNetboxJSONIpamVrfsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONIpamVrfsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ipam.NewIpamVrfsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONIpamVrfsListRead(d *schema.ResourceData, m interface{}) error list, err := client.Ipam.IpamVrfsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_tenancy_contact_assignments_list.go b/netbox/data_netbox_json_tenancy_contact_assignments_list.go index 4cf56cde7..288ee1519 100644 --- a/netbox/data_netbox_json_tenancy_contact_assignments_list.go +++ b/netbox/data_netbox_json_tenancy_contact_assignments_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/tenancy" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONTenancyContactAssignmentsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the tenancy_contact_assignments_list Netbox endpoint.", - Read: dataNetboxJSONTenancyContactAssignmentsListRead, + ReadContext: dataNetboxJSONTenancyContactAssignmentsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONTenancyContactAssignmentsList() *schema.Resource { } } -func dataNetboxJSONTenancyContactAssignmentsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONTenancyContactAssignmentsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := tenancy.NewTenancyContactAssignmentsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONTenancyContactAssignmentsListRead(d *schema.ResourceData, m i list, err := client.Tenancy.TenancyContactAssignmentsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_tenancy_contact_groups_list.go b/netbox/data_netbox_json_tenancy_contact_groups_list.go index 8eda4bd6e..b0235832f 100644 --- a/netbox/data_netbox_json_tenancy_contact_groups_list.go +++ b/netbox/data_netbox_json_tenancy_contact_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/tenancy" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONTenancyContactGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the tenancy_contact_groups_list Netbox endpoint.", - Read: dataNetboxJSONTenancyContactGroupsListRead, + ReadContext: dataNetboxJSONTenancyContactGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONTenancyContactGroupsList() *schema.Resource { } } -func dataNetboxJSONTenancyContactGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONTenancyContactGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := tenancy.NewTenancyContactGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONTenancyContactGroupsListRead(d *schema.ResourceData, m interf list, err := client.Tenancy.TenancyContactGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_tenancy_contact_roles_list.go b/netbox/data_netbox_json_tenancy_contact_roles_list.go index 64d1ba7d9..735cbe6ed 100644 --- a/netbox/data_netbox_json_tenancy_contact_roles_list.go +++ b/netbox/data_netbox_json_tenancy_contact_roles_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/tenancy" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONTenancyContactRolesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the tenancy_contact_roles_list Netbox endpoint.", - Read: dataNetboxJSONTenancyContactRolesListRead, + ReadContext: dataNetboxJSONTenancyContactRolesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONTenancyContactRolesList() *schema.Resource { } } -func dataNetboxJSONTenancyContactRolesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONTenancyContactRolesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := tenancy.NewTenancyContactRolesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONTenancyContactRolesListRead(d *schema.ResourceData, m interfa list, err := client.Tenancy.TenancyContactRolesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_tenancy_contacts_list.go b/netbox/data_netbox_json_tenancy_contacts_list.go index 4cba505c3..d2b2f216d 100644 --- a/netbox/data_netbox_json_tenancy_contacts_list.go +++ b/netbox/data_netbox_json_tenancy_contacts_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/tenancy" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONTenancyContactsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the tenancy_contacts_list Netbox endpoint.", - Read: dataNetboxJSONTenancyContactsListRead, + ReadContext: dataNetboxJSONTenancyContactsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONTenancyContactsList() *schema.Resource { } } -func dataNetboxJSONTenancyContactsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONTenancyContactsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := tenancy.NewTenancyContactsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONTenancyContactsListRead(d *schema.ResourceData, m interface{} list, err := client.Tenancy.TenancyContactsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_tenancy_tenant_groups_list.go b/netbox/data_netbox_json_tenancy_tenant_groups_list.go index cdc398915..fdeacb5f4 100644 --- a/netbox/data_netbox_json_tenancy_tenant_groups_list.go +++ b/netbox/data_netbox_json_tenancy_tenant_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/tenancy" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONTenancyTenantGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the tenancy_tenant_groups_list Netbox endpoint.", - Read: dataNetboxJSONTenancyTenantGroupsListRead, + ReadContext: dataNetboxJSONTenancyTenantGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONTenancyTenantGroupsList() *schema.Resource { } } -func dataNetboxJSONTenancyTenantGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONTenancyTenantGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := tenancy.NewTenancyTenantGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONTenancyTenantGroupsListRead(d *schema.ResourceData, m interfa list, err := client.Tenancy.TenancyTenantGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_tenancy_tenants_list.go b/netbox/data_netbox_json_tenancy_tenants_list.go index ea46fe766..d9fdaff8b 100644 --- a/netbox/data_netbox_json_tenancy_tenants_list.go +++ b/netbox/data_netbox_json_tenancy_tenants_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/tenancy" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONTenancyTenantsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the tenancy_tenants_list Netbox endpoint.", - Read: dataNetboxJSONTenancyTenantsListRead, + ReadContext: dataNetboxJSONTenancyTenantsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONTenancyTenantsList() *schema.Resource { } } -func dataNetboxJSONTenancyTenantsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONTenancyTenantsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := tenancy.NewTenancyTenantsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONTenancyTenantsListRead(d *schema.ResourceData, m interface{}) list, err := client.Tenancy.TenancyTenantsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_users_groups_list.go b/netbox/data_netbox_json_users_groups_list.go index 803f18722..c32f30bd8 100644 --- a/netbox/data_netbox_json_users_groups_list.go +++ b/netbox/data_netbox_json_users_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/users" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONUsersGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the users_groups_list Netbox endpoint.", - Read: dataNetboxJSONUsersGroupsListRead, + ReadContext: dataNetboxJSONUsersGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONUsersGroupsList() *schema.Resource { } } -func dataNetboxJSONUsersGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONUsersGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := users.NewUsersGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONUsersGroupsListRead(d *schema.ResourceData, m interface{}) er list, err := client.Users.UsersGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_users_permissions_list.go b/netbox/data_netbox_json_users_permissions_list.go index fd589d337..4eb468f6c 100644 --- a/netbox/data_netbox_json_users_permissions_list.go +++ b/netbox/data_netbox_json_users_permissions_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/users" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONUsersPermissionsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the users_permissions_list Netbox endpoint.", - Read: dataNetboxJSONUsersPermissionsListRead, + ReadContext: dataNetboxJSONUsersPermissionsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONUsersPermissionsList() *schema.Resource { } } -func dataNetboxJSONUsersPermissionsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONUsersPermissionsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := users.NewUsersPermissionsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONUsersPermissionsListRead(d *schema.ResourceData, m interface{ list, err := client.Users.UsersPermissionsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_users_tokens_list.go b/netbox/data_netbox_json_users_tokens_list.go index b38a1f57c..329e22b24 100644 --- a/netbox/data_netbox_json_users_tokens_list.go +++ b/netbox/data_netbox_json_users_tokens_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/users" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONUsersTokensList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the users_tokens_list Netbox endpoint.", - Read: dataNetboxJSONUsersTokensListRead, + ReadContext: dataNetboxJSONUsersTokensListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONUsersTokensList() *schema.Resource { } } -func dataNetboxJSONUsersTokensListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONUsersTokensListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := users.NewUsersTokensListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONUsersTokensListRead(d *schema.ResourceData, m interface{}) er list, err := client.Users.UsersTokensList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_users_users_list.go b/netbox/data_netbox_json_users_users_list.go index 9354c262a..8282275f1 100644 --- a/netbox/data_netbox_json_users_users_list.go +++ b/netbox/data_netbox_json_users_users_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/users" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONUsersUsersList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the users_users_list Netbox endpoint.", - Read: dataNetboxJSONUsersUsersListRead, + ReadContext: dataNetboxJSONUsersUsersListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONUsersUsersList() *schema.Resource { } } -func dataNetboxJSONUsersUsersListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONUsersUsersListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := users.NewUsersUsersListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONUsersUsersListRead(d *schema.ResourceData, m interface{}) err list, err := client.Users.UsersUsersList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_virtualization_cluster_groups_list.go b/netbox/data_netbox_json_virtualization_cluster_groups_list.go index f99ffeed5..4a5bf087d 100644 --- a/netbox/data_netbox_json_virtualization_cluster_groups_list.go +++ b/netbox/data_netbox_json_virtualization_cluster_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/virtualization" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONVirtualizationClusterGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the virtualization_cluster_groups_list Netbox endpoint.", - Read: dataNetboxJSONVirtualizationClusterGroupsListRead, + ReadContext: dataNetboxJSONVirtualizationClusterGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONVirtualizationClusterGroupsList() *schema.Resource { } } -func dataNetboxJSONVirtualizationClusterGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONVirtualizationClusterGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := virtualization.NewVirtualizationClusterGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONVirtualizationClusterGroupsListRead(d *schema.ResourceData, m list, err := client.Virtualization.VirtualizationClusterGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_virtualization_cluster_types_list.go b/netbox/data_netbox_json_virtualization_cluster_types_list.go index 7597f74b4..863d26c44 100644 --- a/netbox/data_netbox_json_virtualization_cluster_types_list.go +++ b/netbox/data_netbox_json_virtualization_cluster_types_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/virtualization" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONVirtualizationClusterTypesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the virtualization_cluster_types_list Netbox endpoint.", - Read: dataNetboxJSONVirtualizationClusterTypesListRead, + ReadContext: dataNetboxJSONVirtualizationClusterTypesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONVirtualizationClusterTypesList() *schema.Resource { } } -func dataNetboxJSONVirtualizationClusterTypesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONVirtualizationClusterTypesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := virtualization.NewVirtualizationClusterTypesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONVirtualizationClusterTypesListRead(d *schema.ResourceData, m list, err := client.Virtualization.VirtualizationClusterTypesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_virtualization_clusters_list.go b/netbox/data_netbox_json_virtualization_clusters_list.go index 8c09ad33c..2b5446e39 100644 --- a/netbox/data_netbox_json_virtualization_clusters_list.go +++ b/netbox/data_netbox_json_virtualization_clusters_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/virtualization" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONVirtualizationClustersList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the virtualization_clusters_list Netbox endpoint.", - Read: dataNetboxJSONVirtualizationClustersListRead, + ReadContext: dataNetboxJSONVirtualizationClustersListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONVirtualizationClustersList() *schema.Resource { } } -func dataNetboxJSONVirtualizationClustersListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONVirtualizationClustersListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := virtualization.NewVirtualizationClustersListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONVirtualizationClustersListRead(d *schema.ResourceData, m inte list, err := client.Virtualization.VirtualizationClustersList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_virtualization_interfaces_list.go b/netbox/data_netbox_json_virtualization_interfaces_list.go index b0d638890..818e5d3a6 100644 --- a/netbox/data_netbox_json_virtualization_interfaces_list.go +++ b/netbox/data_netbox_json_virtualization_interfaces_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/virtualization" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONVirtualizationInterfacesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the virtualization_interfaces_list Netbox endpoint.", - Read: dataNetboxJSONVirtualizationInterfacesListRead, + ReadContext: dataNetboxJSONVirtualizationInterfacesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONVirtualizationInterfacesList() *schema.Resource { } } -func dataNetboxJSONVirtualizationInterfacesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONVirtualizationInterfacesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := virtualization.NewVirtualizationInterfacesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONVirtualizationInterfacesListRead(d *schema.ResourceData, m in list, err := client.Virtualization.VirtualizationInterfacesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_virtualization_virtual_machines_list.go b/netbox/data_netbox_json_virtualization_virtual_machines_list.go index 4b9e8c9bf..858b9b769 100644 --- a/netbox/data_netbox_json_virtualization_virtual_machines_list.go +++ b/netbox/data_netbox_json_virtualization_virtual_machines_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/virtualization" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONVirtualizationVirtualMachinesList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the virtualization_virtual_machines_list Netbox endpoint.", - Read: dataNetboxJSONVirtualizationVirtualMachinesListRead, + ReadContext: dataNetboxJSONVirtualizationVirtualMachinesListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONVirtualizationVirtualMachinesList() *schema.Resource { } } -func dataNetboxJSONVirtualizationVirtualMachinesListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONVirtualizationVirtualMachinesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := virtualization.NewVirtualizationVirtualMachinesListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONVirtualizationVirtualMachinesListRead(d *schema.ResourceData, list, err := client.Virtualization.VirtualizationVirtualMachinesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_wireless_wireless_lan_groups_list.go b/netbox/data_netbox_json_wireless_wireless_lan_groups_list.go index c622f30e0..65cca67b5 100644 --- a/netbox/data_netbox_json_wireless_wireless_lan_groups_list.go +++ b/netbox/data_netbox_json_wireless_wireless_lan_groups_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/wireless" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONWirelessWirelessLanGroupsList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the wireless_wireless_lan_groups_list Netbox endpoint.", - Read: dataNetboxJSONWirelessWirelessLanGroupsListRead, + ReadContext: dataNetboxJSONWirelessWirelessLanGroupsListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONWirelessWirelessLanGroupsList() *schema.Resource { } } -func dataNetboxJSONWirelessWirelessLanGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONWirelessWirelessLanGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := wireless.NewWirelessWirelessLanGroupsListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONWirelessWirelessLanGroupsListRead(d *schema.ResourceData, m i list, err := client.Wireless.WirelessWirelessLanGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_wireless_wireless_lans_list.go b/netbox/data_netbox_json_wireless_wireless_lans_list.go index b4d15a392..312f7696d 100644 --- a/netbox/data_netbox_json_wireless_wireless_lans_list.go +++ b/netbox/data_netbox_json_wireless_wireless_lans_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/wireless" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONWirelessWirelessLansList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the wireless_wireless_lans_list Netbox endpoint.", - Read: dataNetboxJSONWirelessWirelessLansListRead, + ReadContext: dataNetboxJSONWirelessWirelessLansListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONWirelessWirelessLansList() *schema.Resource { } } -func dataNetboxJSONWirelessWirelessLansListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONWirelessWirelessLansListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := wireless.NewWirelessWirelessLansListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONWirelessWirelessLansListRead(d *schema.ResourceData, m interf list, err := client.Wireless.WirelessWirelessLansList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_json_wireless_wireless_links_list.go b/netbox/data_netbox_json_wireless_wireless_links_list.go index ee3d81ea2..9c5f41412 100644 --- a/netbox/data_netbox_json_wireless_wireless_links_list.go +++ b/netbox/data_netbox_json_wireless_wireless_links_list.go @@ -1,8 +1,10 @@ package netbox import ( + "context" "encoding/json" + "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/wireless" @@ -11,7 +13,7 @@ import ( func dataNetboxJSONWirelessWirelessLinksList() *schema.Resource { return &schema.Resource{ Description: "Get json output from the wireless_wireless_links_list Netbox endpoint.", - Read: dataNetboxJSONWirelessWirelessLinksListRead, + ReadContext: dataNetboxJSONWirelessWirelessLinksListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -29,7 +31,7 @@ func dataNetboxJSONWirelessWirelessLinksList() *schema.Resource { } } -func dataNetboxJSONWirelessWirelessLinksListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSONWirelessWirelessLinksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := wireless.NewWirelessWirelessLinksListParams() @@ -38,7 +40,7 @@ func dataNetboxJSONWirelessWirelessLinksListRead(d *schema.ResourceData, m inter list, err := client.Wireless.WirelessWirelessLinksList(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results) diff --git a/netbox/data_netbox_tenancy_contact.go b/netbox/data_netbox_tenancy_contact.go index 9ba5b66b7..20d4dd72e 100644 --- a/netbox/data_netbox_tenancy_contact.go +++ b/netbox/data_netbox_tenancy_contact.go @@ -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" @@ -12,7 +13,7 @@ import ( func dataNetboxTenancyContact() *schema.Resource { return &schema.Resource{ - Read: dataNetboxTenancyContactRead, + ReadContext: dataNetboxTenancyContactRead, Schema: map[string]*schema.Schema{ "content_type": { @@ -28,7 +29,7 @@ func dataNetboxTenancyContact() *schema.Resource { } } -func dataNetboxTenancyContactRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxTenancyContactRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) name := d.Get("name").(string) @@ -37,14 +38,14 @@ func dataNetboxTenancyContactRead(d *schema.ResourceData, m interface{}) error { list, err := client.Tenancy.TenancyContactsList(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.") } diff --git a/netbox/data_netbox_tenancy_contact_group.go b/netbox/data_netbox_tenancy_contact_group.go index fedbc13d2..5544c98e6 100644 --- a/netbox/data_netbox_tenancy_contact_group.go +++ b/netbox/data_netbox_tenancy_contact_group.go @@ -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" @@ -12,7 +13,7 @@ import ( func dataNetboxTenancyContactGroup() *schema.Resource { return &schema.Resource{ - Read: dataNetboxTenancyContactGroupRead, + ReadContext: dataNetboxTenancyContactGroupRead, Schema: map[string]*schema.Schema{ "content_type": { @@ -28,7 +29,7 @@ func dataNetboxTenancyContactGroup() *schema.Resource { } } -func dataNetboxTenancyContactGroupRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxTenancyContactGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) slug := d.Get("slug").(string) @@ -37,14 +38,14 @@ func dataNetboxTenancyContactGroupRead(d *schema.ResourceData, m interface{}) er list, err := client.Tenancy.TenancyContactGroupsList(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.") } diff --git a/netbox/data_netbox_tenancy_tenant.go b/netbox/data_netbox_tenancy_tenant.go index 5b087d197..1aa0ff841 100644 --- a/netbox/data_netbox_tenancy_tenant.go +++ b/netbox/data_netbox_tenancy_tenant.go @@ -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" @@ -13,7 +14,7 @@ import ( func dataNetboxTenancyTenant() *schema.Resource { return &schema.Resource{ - Read: dataNetboxTenancyTenantRead, + ReadContext: dataNetboxTenancyTenantRead, Schema: map[string]*schema.Schema{ "content_type": { @@ -31,7 +32,7 @@ func dataNetboxTenancyTenant() *schema.Resource { } } -func dataNetboxTenancyTenantRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxTenancyTenantRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) slug := d.Get("slug").(string) @@ -40,14 +41,14 @@ func dataNetboxTenancyTenantRead(d *schema.ResourceData, m interface{}) error { list, err := client.Tenancy.TenancyTenantsList(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.") } diff --git a/netbox/data_netbox_tenancy_tenant_group.go b/netbox/data_netbox_tenancy_tenant_group.go index 7fc38c862..4a36f7f49 100644 --- a/netbox/data_netbox_tenancy_tenant_group.go +++ b/netbox/data_netbox_tenancy_tenant_group.go @@ -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" @@ -13,7 +14,7 @@ import ( func dataNetboxTenancyTenantGroup() *schema.Resource { return &schema.Resource{ - Read: dataNetboxTenancyTenantGroupRead, + ReadContext: dataNetboxTenancyTenantGroupRead, Schema: map[string]*schema.Schema{ "content_type": { @@ -31,8 +32,8 @@ func dataNetboxTenancyTenantGroup() *schema.Resource { } } -func dataNetboxTenancyTenantGroupRead(d *schema.ResourceData, - m interface{}) error { +func dataNetboxTenancyTenantGroupRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) @@ -42,14 +43,14 @@ func dataNetboxTenancyTenantGroupRead(d *schema.ResourceData, list, err := client.Tenancy.TenancyTenantGroupsList(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.") } diff --git a/netbox/data_netbox_tenancy_tenant_role.go b/netbox/data_netbox_tenancy_tenant_role.go index ae1781d68..a3add855c 100644 --- a/netbox/data_netbox_tenancy_tenant_role.go +++ b/netbox/data_netbox_tenancy_tenant_role.go @@ -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" @@ -13,7 +14,7 @@ import ( func dataNetboxTenancyContactRole() *schema.Resource { return &schema.Resource{ - Read: dataNetboxTenancyContactRoleRead, + ReadContext: dataNetboxTenancyContactRoleRead, Schema: map[string]*schema.Schema{ "content_type": { @@ -31,8 +32,8 @@ func dataNetboxTenancyContactRole() *schema.Resource { } } -func dataNetboxTenancyContactRoleRead(d *schema.ResourceData, - m interface{}) error { +func dataNetboxTenancyContactRoleRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) @@ -42,14 +43,14 @@ func dataNetboxTenancyContactRoleRead(d *schema.ResourceData, list, err := client.Tenancy.TenancyContactRolesList(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.") } diff --git a/netbox/data_netbox_virtualization_cluster.go b/netbox/data_netbox_virtualization_cluster.go index fca30f8e8..94c969812 100644 --- a/netbox/data_netbox_virtualization_cluster.go +++ b/netbox/data_netbox_virtualization_cluster.go @@ -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" @@ -12,7 +13,7 @@ import ( func dataNetboxVirtualizationCluster() *schema.Resource { return &schema.Resource{ - Read: dataNetboxVirtualizationClusterRead, + ReadContext: dataNetboxVirtualizationClusterRead, Schema: map[string]*schema.Schema{ "content_type": { @@ -28,8 +29,8 @@ func dataNetboxVirtualizationCluster() *schema.Resource { } } -func dataNetboxVirtualizationClusterRead(d *schema.ResourceData, - m interface{}) error { +func dataNetboxVirtualizationClusterRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) name := d.Get("name").(string) @@ -39,14 +40,14 @@ func dataNetboxVirtualizationClusterRead(d *schema.ResourceData, list, err := client.Virtualization.VirtualizationClustersList(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.") } diff --git a/netbox/provider.go b/netbox/provider.go index 7f7201744..316924151 100644 --- a/netbox/provider.go +++ b/netbox/provider.go @@ -1,12 +1,14 @@ package netbox import ( + "context" "crypto/tls" "fmt" "net/http" runtimeclient "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/smutel/go-netbox/netbox/client" ) @@ -169,11 +171,11 @@ func Provider() *schema.Provider { "netbox_virtualization_interface": resourceNetboxVirtualizationInterface(), "netbox_virtualization_vm": resourceNetboxVirtualizationVM(), }, - ConfigureFunc: configureProvider, + ConfigureContextFunc: configureProvider, } } -func configureProvider(d *schema.ResourceData) (interface{}, error) { +func configureProvider(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { url := d.Get("url").(string) basepath := d.Get("basepath").(string) token := d.Get("token").(string) diff --git a/netbox/resource_netbox_ipam_aggregate.go b/netbox/resource_netbox_ipam_aggregate.go index 9255821ce..dab6cc4d4 100644 --- a/netbox/resource_netbox_ipam_aggregate.go +++ b/netbox/resource_netbox_ipam_aggregate.go @@ -1,11 +1,13 @@ package netbox import ( + "context" "fmt" "strconv" "time" "github.com/go-openapi/strfmt" + "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" @@ -15,12 +17,12 @@ import ( func resourceNetboxIpamAggregate() *schema.Resource { return &schema.Resource{ - Description: "Manage an aggregate (ipam module) within Netbox.", - Create: resourceNetboxIpamAggregateCreate, - Read: resourceNetboxIpamAggregateRead, - Update: resourceNetboxIpamAggregateUpdate, - Delete: resourceNetboxIpamAggregateDelete, - Exists: resourceNetboxIpamAggregateExists, + Description: "Manage an aggregate (ipam module) within Netbox.", + CreateContext: resourceNetboxIpamAggregateCreate, + ReadContext: resourceNetboxIpamAggregateRead, + UpdateContext: resourceNetboxIpamAggregateUpdate, + DeleteContext: resourceNetboxIpamAggregateDelete, + Exists: resourceNetboxIpamAggregateExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -112,8 +114,8 @@ func resourceNetboxIpamAggregate() *schema.Resource { } } -func resourceNetboxIpamAggregateCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamAggregateCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceCustomFields := d.Get("custom_field").(*schema.Set).List() @@ -138,7 +140,7 @@ func resourceNetboxIpamAggregateCreate(d *schema.ResourceData, if dateAdded != "" { dateAddedTime, err := time.Parse("2006-01-02", dateAdded) if err != nil { - return err + return diag.FromErr(err) } dateAddedFmt := strfmt.Date(dateAddedTime) @@ -149,36 +151,36 @@ func resourceNetboxIpamAggregateCreate(d *schema.ResourceData, resourceCreated, err := client.Ipam.IpamAggregatesCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxIpamAggregateRead(d, m) + return resourceNetboxIpamAggregateRead(ctx, d, m) } -func resourceNetboxIpamAggregateRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamAggregateRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := ipam.NewIpamAggregatesListParams().WithID(&resourceID) resources, err := client.Ipam.IpamAggregatesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var dateAdded string @@ -189,7 +191,7 @@ func resourceNetboxIpamAggregateRead(d *schema.ResourceData, } if err = d.Set("date_added", dateAdded); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -200,24 +202,24 @@ func resourceNetboxIpamAggregateRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("prefix", resource.Prefix); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } if resource.Rir == nil { if err = d.Set("rir_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("rir_id", resource.Rir.ID); err != nil { - return err + return diag.FromErr(err) } } @@ -229,8 +231,8 @@ func resourceNetboxIpamAggregateRead(d *schema.ResourceData, return nil } -func resourceNetboxIpamAggregateUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamAggregateUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableAggregate{} @@ -253,7 +255,7 @@ func resourceNetboxIpamAggregateUpdate(d *schema.ResourceData, if dateAdded != "" { dateAddedTime, err := time.Parse("2006-01-02", dateAdded) if err != nil { - return err + return diag.FromErr(err) } dateAddedFmt := strfmt.Date(dateAddedTime) @@ -276,26 +278,26 @@ func resourceNetboxIpamAggregateUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Ipam.IpamAggregatesPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxIpamAggregateRead(d, m) + return resourceNetboxIpamAggregateRead(ctx, d, m) } -func resourceNetboxIpamAggregateDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamAggregateDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxIpamAggregateExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -304,12 +306,12 @@ func resourceNetboxIpamAggregateDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource := ipam.NewIpamAggregatesDeleteParams().WithID(id) if _, err := client.Ipam.IpamAggregatesDelete(resource, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_ipam_ip_addresses.go b/netbox/resource_netbox_ipam_ip_addresses.go index f09b0bf42..05531e327 100644 --- a/netbox/resource_netbox_ipam_ip_addresses.go +++ b/netbox/resource_netbox_ipam_ip_addresses.go @@ -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" @@ -14,12 +15,12 @@ import ( func resourceNetboxIpamIPAddresses() *schema.Resource { return &schema.Resource{ - Description: "Manage an IP address (ipam module) within Netbox.", - Create: resourceNetboxIpamIPAddressesCreate, - Read: resourceNetboxIpamIPAddressesRead, - Update: resourceNetboxIpamIPAddressesUpdate, - Delete: resourceNetboxIpamIPAddressesDelete, - Exists: resourceNetboxIpamIPAddressesExists, + Description: "Manage an IP address (ipam module) within Netbox.", + CreateContext: resourceNetboxIpamIPAddressesCreate, + ReadContext: resourceNetboxIpamIPAddressesRead, + UpdateContext: resourceNetboxIpamIPAddressesUpdate, + DeleteContext: resourceNetboxIpamIPAddressesDelete, + Exists: resourceNetboxIpamIPAddressesExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -154,8 +155,8 @@ func resourceNetboxIpamIPAddresses() *schema.Resource { } } -func resourceNetboxIpamIPAddressesCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamIPAddressesCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) address := d.Get("address").(string) @@ -193,7 +194,7 @@ func resourceNetboxIpamIPAddressesCreate(d *schema.ResourceData, var err error info, err = getInfoForPrimary(m, objectID) if err != nil { - return err + return diag.FromErr(err) } } } @@ -215,45 +216,45 @@ func resourceNetboxIpamIPAddressesCreate(d *schema.ResourceData, resourceCreated, err := client.Ipam.IpamIPAddressesCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) err = updatePrimaryStatus(client, info, resourceCreated.Payload.ID) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxIpamIPAddressesRead(d, m) + return resourceNetboxIpamIPAddressesRead(ctx, d, m) } -func resourceNetboxIpamIPAddressesRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamIPAddressesRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := ipam.NewIpamIPAddressesListParams().WithID(&resourceID) resources, err := client.Ipam.IpamIPAddressesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("address", resource.Address); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -264,7 +265,7 @@ func resourceNetboxIpamIPAddressesRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } var dnsName interface{} @@ -275,30 +276,30 @@ func resourceNetboxIpamIPAddressesRead(d *schema.ResourceData, } if err = d.Set("dns_name", dnsName); err != nil { - return err + return diag.FromErr(err) } if resource.NatInside == nil { if err = d.Set("nat_inside_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("nat_inside_id", resource.NatInside.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.AssignedObjectID == nil { if err = d.Set("object_id", nil); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("primary_ip4", false); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("object_id", resource.AssignedObjectID); err != nil { - return err + return diag.FromErr(err) } var info InfosForPrimary @@ -307,16 +308,16 @@ func resourceNetboxIpamIPAddressesRead(d *schema.ResourceData, var err error info, err = getInfoForPrimary(m, *resource.AssignedObjectID) if err != nil { - return err + return diag.FromErr(err) } if info.vmPrimaryIP4ID == resource.ID { if err = d.Set("primary_ip4", true); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("primary_ip4", false); err != nil { - return err + return diag.FromErr(err) } } } @@ -328,55 +329,55 @@ func resourceNetboxIpamIPAddressesRead(d *schema.ResourceData, *objectType = VMInterfaceType if err = d.Set("object_type", *objectType); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("object_type", nil); err != nil { - return err + return diag.FromErr(err) } } if resource.Role == nil { if err = d.Set("role", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("role", resource.Role.Value); err != nil { - return err + return diag.FromErr(err) } } if resource.Status == nil { if err = d.Set("status", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("status", resource.Status.Value); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } if resource.Tenant == nil { if err = d.Set("tenant_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("tenant_id", resource.Tenant.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Vrf == nil { if err = d.Set("vrf_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("vrf_id", resource.Vrf.ID); err != nil { - return err + return diag.FromErr(err) } } @@ -389,8 +390,8 @@ func resourceNetboxIpamIPAddressesRead(d *schema.ResourceData, return nil } -func resourceNetboxIpamIPAddressesUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamIPAddressesUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableIPAddress{} // primary_ip4 := false @@ -474,14 +475,14 @@ func resourceNetboxIpamIPAddressesUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Ipam.IpamIPAddressesPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } /* @@ -495,7 +496,7 @@ func resourceNetboxIpamIPAddressesUpdate(d *schema.ResourceData, * var err error * info, err = getInfoForPrimary(m, objectID) * if err != nil { - * return err + * return diag.FromErr(err) * } * } * } @@ -505,26 +506,26 @@ func resourceNetboxIpamIPAddressesUpdate(d *schema.ResourceData, * if isPrimary { * ipID, err = strconv.ParseInt(d.Id(), 10, 64) * if err != nil { - * return fmt.Errorf("Unable to convert ID into int64") + * return diag.Errorf("Unable to convert ID into int64") * } * } * err = updatePrimaryStatus(client, info, ipID) * if err != nil { - * return err + * return diag.FromErr(err) * } * } */ - return resourceNetboxIpamIPAddressesRead(d, m) + return resourceNetboxIpamIPAddressesRead(ctx, d, m) } -func resourceNetboxIpamIPAddressesDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamIPAddressesDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxIpamIPAddressesExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -533,12 +534,12 @@ func resourceNetboxIpamIPAddressesDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource := ipam.NewIpamIPAddressesDeleteParams().WithID(id) if _, err := client.Ipam.IpamIPAddressesDelete(resource, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_ipam_prefix.go b/netbox/resource_netbox_ipam_prefix.go index 763df53ad..06badb7ee 100644 --- a/netbox/resource_netbox_ipam_prefix.go +++ b/netbox/resource_netbox_ipam_prefix.go @@ -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" @@ -13,12 +14,12 @@ import ( func resourceNetboxIpamPrefix() *schema.Resource { return &schema.Resource{ - Description: "Manage a prefix (ipam module) within Netbox.", - Create: resourceNetboxIpamPrefixCreate, - Read: resourceNetboxIpamPrefixRead, - Update: resourceNetboxIpamPrefixUpdate, - Delete: resourceNetboxIpamPrefixDelete, - Exists: resourceNetboxIpamPrefixExists, + Description: "Manage a prefix (ipam module) within Netbox.", + CreateContext: resourceNetboxIpamPrefixCreate, + ReadContext: resourceNetboxIpamPrefixRead, + UpdateContext: resourceNetboxIpamPrefixUpdate, + DeleteContext: resourceNetboxIpamPrefixDelete, + Exists: resourceNetboxIpamPrefixExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -130,8 +131,8 @@ func resourceNetboxIpamPrefix() *schema.Resource { } } -func resourceNetboxIpamPrefixCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamPrefixCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceCustomFields := d.Get("custom_field").(*schema.Set).List() @@ -180,36 +181,36 @@ func resourceNetboxIpamPrefixCreate(d *schema.ResourceData, resourceCreated, err := client.Ipam.IpamPrefixesCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxIpamPrefixRead(d, m) + return resourceNetboxIpamPrefixRead(ctx, d, m) } -func resourceNetboxIpamPrefixRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamPrefixRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := ipam.NewIpamPrefixesListParams().WithID(&resourceID) resources, err := client.Ipam.IpamPrefixesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -220,78 +221,78 @@ func resourceNetboxIpamPrefixRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("is_pool", resource.IsPool); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("prefix", resource.Prefix); err != nil { - return err + return diag.FromErr(err) } if resource.Role == nil { if err = d.Set("role_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("role_id", resource.Role.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Site == nil { if err = d.Set("site_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("site_id", resource.Site.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Status == nil { if err = d.Set("status", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("status", resource.Status.Value); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } if resource.Tenant == nil { if err = d.Set("tenant_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("tenant_id", resource.Tenant.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Vlan == nil { if err = d.Set("vlan_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("vlan_id", resource.Vlan.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Vrf == nil { if err = d.Set("vrf_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("vrf_id", resource.Vrf.ID); err != nil { - return err + return diag.FromErr(err) } } @@ -303,8 +304,8 @@ func resourceNetboxIpamPrefixRead(d *schema.ResourceData, return nil } -func resourceNetboxIpamPrefixUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamPrefixUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritablePrefix{} @@ -374,26 +375,26 @@ func resourceNetboxIpamPrefixUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Ipam.IpamPrefixesPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxIpamPrefixRead(d, m) + return resourceNetboxIpamPrefixRead(ctx, d, m) } -func resourceNetboxIpamPrefixDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamPrefixDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxIpamPrefixExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -402,12 +403,12 @@ func resourceNetboxIpamPrefixDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource := ipam.NewIpamPrefixesDeleteParams().WithID(id) if _, err := client.Ipam.IpamPrefixesDelete(resource, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_ipam_service.go b/netbox/resource_netbox_ipam_service.go index dd478c31d..c1a168041 100644 --- a/netbox/resource_netbox_ipam_service.go +++ b/netbox/resource_netbox_ipam_service.go @@ -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" @@ -13,12 +14,12 @@ import ( func resourceNetboxIpamService() *schema.Resource { return &schema.Resource{ - Description: "Manage an service (ipam module) within Netbox.", - Create: resourceNetboxIpamServiceCreate, - Read: resourceNetboxIpamServiceRead, - Update: resourceNetboxIpamServiceUpdate, - Delete: resourceNetboxIpamServiceDelete, - Exists: resourceNetboxIpamServiceExists, + Description: "Manage an service (ipam module) within Netbox.", + CreateContext: resourceNetboxIpamServiceCreate, + ReadContext: resourceNetboxIpamServiceRead, + UpdateContext: resourceNetboxIpamServiceUpdate, + DeleteContext: resourceNetboxIpamServiceDelete, + Exists: resourceNetboxIpamServiceExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -124,8 +125,8 @@ func resourceNetboxIpamService() *schema.Resource { } } -func resourceNetboxIpamServiceCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamServiceCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceCustomFields := d.Get("custom_field").(*schema.Set).List() @@ -171,35 +172,35 @@ func resourceNetboxIpamServiceCreate(d *schema.ResourceData, resourceCreated, err := client.Ipam.IpamServicesCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxIpamServiceRead(d, m) + return resourceNetboxIpamServiceRead(ctx, d, m) } -func resourceNetboxIpamServiceRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamServiceRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := ipam.NewIpamServicesListParams().WithID(&resourceID) resources, err := client.Ipam.IpamServicesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -210,16 +211,16 @@ func resourceNetboxIpamServiceRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if resource.Device == nil { if err = d.Set("device_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("device_id", resource.Device.ID); err != nil { - return err + return diag.FromErr(err) } } @@ -229,33 +230,33 @@ func resourceNetboxIpamServiceRead(d *schema.ResourceData, IPaddressesInt = append(IPaddressesInt, ip.ID) } if err = d.Set("ip_addresses_id", IPaddressesInt); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } ports := resource.Ports if err = d.Set("ports", ports); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("protocol", resource.Protocol.Value); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } if resource.VirtualMachine == nil { if err = d.Set("virtualmachine_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("virtualmachine_id", resource.VirtualMachine.ID); err != nil { - return err + return diag.FromErr(err) } } @@ -267,8 +268,8 @@ func resourceNetboxIpamServiceRead(d *schema.ResourceData, return nil } -func resourceNetboxIpamServiceUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamServiceUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableService{} @@ -327,25 +328,25 @@ func resourceNetboxIpamServiceUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Ipam.IpamServicesPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxIpamServiceRead(d, m) + return resourceNetboxIpamServiceRead(ctx, d, m) } -func resourceNetboxIpamServiceDelete(d *schema.ResourceData, m interface{}) error { +func resourceNetboxIpamServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxIpamServiceExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -354,12 +355,12 @@ func resourceNetboxIpamServiceDelete(d *schema.ResourceData, m interface{}) erro id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource := ipam.NewIpamServicesDeleteParams().WithID(id) if _, err := client.Ipam.IpamServicesDelete(resource, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_ipam_vlan.go b/netbox/resource_netbox_ipam_vlan.go index 81b249915..674e6b905 100644 --- a/netbox/resource_netbox_ipam_vlan.go +++ b/netbox/resource_netbox_ipam_vlan.go @@ -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" @@ -13,12 +14,12 @@ import ( func resourceNetboxIpamVlan() *schema.Resource { return &schema.Resource{ - Description: "Manage a vlan (ipam module) within Netbox.", - Create: resourceNetboxIpamVlanCreate, - Read: resourceNetboxIpamVlanRead, - Update: resourceNetboxIpamVlanUpdate, - Delete: resourceNetboxIpamVlanDelete, - Exists: resourceNetboxIpamVlanExists, + Description: "Manage a vlan (ipam module) within Netbox.", + CreateContext: resourceNetboxIpamVlanCreate, + ReadContext: resourceNetboxIpamVlanRead, + UpdateContext: resourceNetboxIpamVlanUpdate, + DeleteContext: resourceNetboxIpamVlanDelete, + Exists: resourceNetboxIpamVlanExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -124,8 +125,8 @@ func resourceNetboxIpamVlan() *schema.Resource { } } -func resourceNetboxIpamVlanCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamVlanCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceCustomFields := d.Get("custom_field").(*schema.Set).List() @@ -169,35 +170,35 @@ func resourceNetboxIpamVlanCreate(d *schema.ResourceData, resourceCreated, err := client.Ipam.IpamVlansCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxIpamVlanRead(d, m) + return resourceNetboxIpamVlanRead(ctx, d, m) } -func resourceNetboxIpamVlanRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamVlanRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := ipam.NewIpamVlansListParams().WithID(&resourceID) resources, err := client.Ipam.IpamVlansList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -208,69 +209,69 @@ func resourceNetboxIpamVlanRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if resource.Group == nil { if err = d.Set("vlan_group_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("vlan_group_id", resource.Group.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if resource.Role == nil { if err = d.Set("role_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("role_id", resource.Role.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Site == nil { if err = d.Set("site_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("site_id", resource.Site.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Status == nil { if err = d.Set("status", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("status", resource.Status.Value); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } if resource.Tenant == nil { if err = d.Set("tenant_id", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("tenant_id", resource.Tenant.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("vlan_id", resource.Vid); err != nil { - return err + return diag.FromErr(err) } return nil @@ -281,8 +282,8 @@ func resourceNetboxIpamVlanRead(d *schema.ResourceData, return nil } -func resourceNetboxIpamVlanUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamVlanUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableVLAN{} @@ -347,25 +348,25 @@ func resourceNetboxIpamVlanUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Ipam.IpamVlansPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxIpamVlanRead(d, m) + return resourceNetboxIpamVlanRead(ctx, d, m) } -func resourceNetboxIpamVlanDelete(d *schema.ResourceData, m interface{}) error { +func resourceNetboxIpamVlanDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxIpamVlanExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -374,12 +375,12 @@ func resourceNetboxIpamVlanDelete(d *schema.ResourceData, m interface{}) error { id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource := ipam.NewIpamVlansDeleteParams().WithID(id) if _, err := client.Ipam.IpamVlansDelete(resource, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_ipam_vlan_group.go b/netbox/resource_netbox_ipam_vlan_group.go index fea7049b3..5e48e9f6a 100644 --- a/netbox/resource_netbox_ipam_vlan_group.go +++ b/netbox/resource_netbox_ipam_vlan_group.go @@ -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" @@ -14,12 +15,12 @@ import ( func resourceNetboxIpamVlanGroup() *schema.Resource { return &schema.Resource{ - Description: "Manage a vlan group (ipam module) within Netbox.", - Create: resourceNetboxIpamVlanGroupCreate, - Read: resourceNetboxIpamVlanGroupRead, - Update: resourceNetboxIpamVlanGroupUpdate, - Delete: resourceNetboxIpamVlanGroupDelete, - Exists: resourceNetboxIpamVlanGroupExists, + Description: "Manage a vlan group (ipam module) within Netbox.", + CreateContext: resourceNetboxIpamVlanGroupCreate, + ReadContext: resourceNetboxIpamVlanGroupRead, + UpdateContext: resourceNetboxIpamVlanGroupUpdate, + DeleteContext: resourceNetboxIpamVlanGroupDelete, + Exists: resourceNetboxIpamVlanGroupExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -67,8 +68,8 @@ func resourceNetboxIpamVlanGroup() *schema.Resource { } } -func resourceNetboxIpamVlanGroupCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamVlanGroupCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) groupName := d.Get("name").(string) @@ -85,40 +86,40 @@ func resourceNetboxIpamVlanGroupCreate(d *schema.ResourceData, resourceCreated, err := client.Ipam.IpamVlanGroupsCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxIpamVlanGroupRead(d, m) + return resourceNetboxIpamVlanGroupRead(ctx, d, m) } -func resourceNetboxIpamVlanGroupRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamVlanGroupRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := ipam.NewIpamVlanGroupsListParams().WithID(&resourceID) resources, err := client.Ipam.IpamVlanGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("slug", resource.Slug); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } return nil @@ -129,8 +130,8 @@ func resourceNetboxIpamVlanGroupRead(d *schema.ResourceData, return nil } -func resourceNetboxIpamVlanGroupUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxIpamVlanGroupUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.VLANGroup{} @@ -149,25 +150,25 @@ func resourceNetboxIpamVlanGroupUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Ipam.IpamVlanGroupsPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxIpamVlanGroupRead(d, m) + return resourceNetboxIpamVlanGroupRead(ctx, d, m) } -func resourceNetboxIpamVlanGroupDelete(d *schema.ResourceData, m interface{}) error { +func resourceNetboxIpamVlanGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxIpamVlanGroupExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -176,12 +177,12 @@ func resourceNetboxIpamVlanGroupDelete(d *schema.ResourceData, m interface{}) er id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource := ipam.NewIpamVlanGroupsDeleteParams().WithID(id) if _, err := client.Ipam.IpamVlanGroupsDelete(resource, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_tenancy_contact.go b/netbox/resource_netbox_tenancy_contact.go index a8b1a37da..64707d03d 100644 --- a/netbox/resource_netbox_tenancy_contact.go +++ b/netbox/resource_netbox_tenancy_contact.go @@ -1,10 +1,12 @@ package netbox import ( + "context" "fmt" "strconv" "github.com/go-openapi/strfmt" + "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" @@ -14,12 +16,12 @@ import ( func resourceNetboxTenancyContact() *schema.Resource { return &schema.Resource{ - Description: "Manage a contact (tenancy module) within Netbox.", - Create: resourceNetboxTenancyContactCreate, - Read: resourceNetboxTenancyContactRead, - Update: resourceNetboxTenancyContactUpdate, - Delete: resourceNetboxTenancyContactDelete, - Exists: resourceNetboxTenancyContactExists, + Description: "Manage a contact (tenancy module) within Netbox.", + CreateContext: resourceNetboxTenancyContactCreate, + ReadContext: resourceNetboxTenancyContactRead, + UpdateContext: resourceNetboxTenancyContactUpdate, + DeleteContext: resourceNetboxTenancyContactDelete, + Exists: resourceNetboxTenancyContactExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -133,8 +135,8 @@ func resourceNetboxTenancyContact() *schema.Resource { } } -func resourceNetboxTenancyContactCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) address := d.Get("address").(string) @@ -167,23 +169,23 @@ func resourceNetboxTenancyContactCreate(d *schema.ResourceData, resourceCreated, err := client.Tenancy.TenancyContactsCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxTenancyContactRead(d, m) + return resourceNetboxTenancyContactRead(ctx, d, m) } -func resourceNetboxTenancyContactRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := tenancy.NewTenancyContactsListParams().WithID(&resourceID) resources, err := client.Tenancy.TenancyContactsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { @@ -196,7 +198,7 @@ func resourceNetboxTenancyContactRead(d *schema.ResourceData, } if err = d.Set("address", address); err != nil { - return err + return diag.FromErr(err) } var comments interface{} @@ -207,28 +209,28 @@ func resourceNetboxTenancyContactRead(d *schema.ResourceData, } if err = d.Set("comments", comments); err != nil { - return err + return diag.FromErr(err) } if resource.Group == nil { if err = d.Set("contact_group_id", 0); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("contact_group_id", resource.Group.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var email interface{} @@ -239,11 +241,11 @@ func resourceNetboxTenancyContactRead(d *schema.ResourceData, } if err = d.Set("email", email); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } var phone interface{} @@ -254,11 +256,11 @@ func resourceNetboxTenancyContactRead(d *schema.ResourceData, } if err = d.Set("phone", phone); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } var title interface{} @@ -269,7 +271,7 @@ func resourceNetboxTenancyContactRead(d *schema.ResourceData, } if err = d.Set("title", title); err != nil { - return err + return diag.FromErr(err) } return nil @@ -280,8 +282,8 @@ func resourceNetboxTenancyContactRead(d *schema.ResourceData, return nil } -func resourceNetboxTenancyContactUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableContact{} @@ -351,26 +353,26 @@ func resourceNetboxTenancyContactUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Tenancy.TenancyContactsPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxTenancyContactRead(d, m) + return resourceNetboxTenancyContactRead(ctx, d, m) } -func resourceNetboxTenancyContactDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxTenancyContactExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -379,12 +381,12 @@ func resourceNetboxTenancyContactDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } p := tenancy.NewTenancyContactsDeleteParams().WithID(id) if _, err := client.Tenancy.TenancyContactsDelete(p, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_tenancy_contact_assignment.go b/netbox/resource_netbox_tenancy_contact_assignment.go index 04d878cb2..4600514bc 100644 --- a/netbox/resource_netbox_tenancy_contact_assignment.go +++ b/netbox/resource_netbox_tenancy_contact_assignment.go @@ -1,9 +1,11 @@ package netbox import ( + "context" "fmt" "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" @@ -13,12 +15,12 @@ import ( func resourceNetboxTenancyContactAssignment() *schema.Resource { return &schema.Resource{ - Description: "Link a contact (tenancy module) to another resource within Netbox.", - Create: resourceNetboxTenancyContactAssignmentCreate, - Read: resourceNetboxTenancyContactAssignmentRead, - Update: resourceNetboxTenancyContactAssignmentUpdate, - Delete: resourceNetboxTenancyContactAssignmentDelete, - Exists: resourceNetboxTenancyContactAssignmentExists, + Description: "Link a contact (tenancy module) to another resource within Netbox.", + CreateContext: resourceNetboxTenancyContactAssignmentCreate, + ReadContext: resourceNetboxTenancyContactAssignmentRead, + UpdateContext: resourceNetboxTenancyContactAssignmentUpdate, + DeleteContext: resourceNetboxTenancyContactAssignmentDelete, + Exists: resourceNetboxTenancyContactAssignmentExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -56,8 +58,8 @@ func resourceNetboxTenancyContactAssignment() *schema.Resource { } } -func resourceNetboxTenancyContactAssignmentCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactAssignmentCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) fmt.Println(client) @@ -79,51 +81,51 @@ func resourceNetboxTenancyContactAssignmentCreate(d *schema.ResourceData, resourceCreated, err := client.Tenancy.TenancyContactAssignmentsCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxTenancyContactAssignmentRead(d, m) + return resourceNetboxTenancyContactAssignmentRead(ctx, d, m) } -func resourceNetboxTenancyContactAssignmentRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactAssignmentRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := tenancy.NewTenancyContactAssignmentsListParams().WithID(&resourceID) resources, err := client.Tenancy.TenancyContactAssignmentsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("contact_id", resource.Contact.ID); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("content_type", resource.ContentType); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("object_id", resource.ObjectID); err != nil { - return err + return diag.FromErr(err) } if resource.Priority == nil { if err = d.Set("priority", nil); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("priority", resource.Priority.Value); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("contact_role_id", resource.Role.ID); err != nil { - return err + return diag.FromErr(err) } return nil @@ -134,8 +136,8 @@ func resourceNetboxTenancyContactAssignmentRead(d *schema.ResourceData, return nil } -func resourceNetboxTenancyContactAssignmentUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactAssignmentUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableContactAssignment{} @@ -159,26 +161,26 @@ func resourceNetboxTenancyContactAssignmentUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Tenancy.TenancyContactAssignmentsPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxTenancyContactAssignmentRead(d, m) + return resourceNetboxTenancyContactAssignmentRead(ctx, d, m) } -func resourceNetboxTenancyContactAssignmentDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactAssignmentDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxTenancyContactAssignmentExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -187,12 +189,12 @@ func resourceNetboxTenancyContactAssignmentDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } p := tenancy.NewTenancyContactAssignmentsDeleteParams().WithID(id) if _, err := client.Tenancy.TenancyContactAssignmentsDelete(p, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_tenancy_contact_group.go b/netbox/resource_netbox_tenancy_contact_group.go index 17e123c6c..b806e1fd0 100644 --- a/netbox/resource_netbox_tenancy_contact_group.go +++ b/netbox/resource_netbox_tenancy_contact_group.go @@ -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" @@ -14,12 +15,12 @@ import ( func resourceNetboxTenancyContactGroup() *schema.Resource { return &schema.Resource{ - Description: "Manage a contact group (tenancy module) within Netbox.", - Create: resourceNetboxTenancyContactGroupCreate, - Read: resourceNetboxTenancyContactGroupRead, - Update: resourceNetboxTenancyContactGroupUpdate, - Delete: resourceNetboxTenancyContactGroupDelete, - Exists: resourceNetboxTenancyContactGroupExists, + Description: "Manage a contact group (tenancy module) within Netbox.", + CreateContext: resourceNetboxTenancyContactGroupCreate, + ReadContext: resourceNetboxTenancyContactGroupRead, + UpdateContext: resourceNetboxTenancyContactGroupUpdate, + DeleteContext: resourceNetboxTenancyContactGroupDelete, + Exists: resourceNetboxTenancyContactGroupExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -106,8 +107,8 @@ func resourceNetboxTenancyContactGroup() *schema.Resource { } } -func resourceNetboxTenancyContactGroupCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactGroupCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceCustomFields := d.Get("custom_field").(*schema.Set).List() @@ -134,36 +135,36 @@ func resourceNetboxTenancyContactGroupCreate(d *schema.ResourceData, resourceCreated, err := client.Tenancy.TenancyContactGroupsCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxTenancyContactGroupRead(d, m) + return resourceNetboxTenancyContactGroupRead(ctx, d, m) } -func resourceNetboxTenancyContactGroupRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactGroupRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := tenancy.NewTenancyContactGroupsListParams().WithID(&resourceID) resources, err := client.Tenancy.TenancyContactGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -174,29 +175,29 @@ func resourceNetboxTenancyContactGroupRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if resource.Parent == nil { if err = d.Set("parent_id", 0); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("parent_id", resource.Parent.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("slug", resource.Slug); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } return nil @@ -207,8 +208,8 @@ func resourceNetboxTenancyContactGroupRead(d *schema.ResourceData, return nil } -func resourceNetboxTenancyContactGroupUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactGroupUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableContactGroup{} @@ -243,26 +244,26 @@ func resourceNetboxTenancyContactGroupUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Tenancy.TenancyContactGroupsPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxTenancyContactGroupRead(d, m) + return resourceNetboxTenancyContactGroupRead(ctx, d, m) } -func resourceNetboxTenancyContactGroupDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactGroupDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxTenancyContactGroupExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -271,12 +272,12 @@ func resourceNetboxTenancyContactGroupDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } p := tenancy.NewTenancyContactGroupsDeleteParams().WithID(id) if _, err := client.Tenancy.TenancyContactGroupsDelete(p, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_tenancy_contact_role.go b/netbox/resource_netbox_tenancy_contact_role.go index 8a2efc871..cd5f971e6 100644 --- a/netbox/resource_netbox_tenancy_contact_role.go +++ b/netbox/resource_netbox_tenancy_contact_role.go @@ -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" @@ -14,12 +15,12 @@ import ( func resourceNetboxTenancyContactRole() *schema.Resource { return &schema.Resource{ - Description: "Manage a contact role (tenancy module) within Netbox.", - Create: resourceNetboxTenancyContactRoleCreate, - Read: resourceNetboxTenancyContactRoleRead, - Update: resourceNetboxTenancyContactRoleUpdate, - Delete: resourceNetboxTenancyContactRoleDelete, - Exists: resourceNetboxTenancyContactRoleExists, + Description: "Manage a contact role (tenancy module) within Netbox.", + CreateContext: resourceNetboxTenancyContactRoleCreate, + ReadContext: resourceNetboxTenancyContactRoleRead, + UpdateContext: resourceNetboxTenancyContactRoleUpdate, + DeleteContext: resourceNetboxTenancyContactRoleDelete, + Exists: resourceNetboxTenancyContactRoleExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -100,8 +101,8 @@ func resourceNetboxTenancyContactRole() *schema.Resource { } } -func resourceNetboxTenancyContactRoleCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactRoleCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceCustomFields := d.Get("custom_field").(*schema.Set).List() @@ -123,36 +124,36 @@ func resourceNetboxTenancyContactRoleCreate(d *schema.ResourceData, resourceCreated, err := client.Tenancy.TenancyContactRolesCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxTenancyContactRoleRead(d, m) + return resourceNetboxTenancyContactRoleRead(ctx, d, m) } -func resourceNetboxTenancyContactRoleRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactRoleRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := tenancy.NewTenancyContactRolesListParams().WithID(&resourceID) resources, err := client.Tenancy.TenancyContactRolesList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -163,19 +164,19 @@ func resourceNetboxTenancyContactRoleRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("slug", resource.Slug); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } return nil @@ -186,8 +187,8 @@ func resourceNetboxTenancyContactRoleRead(d *schema.ResourceData, return nil } -func resourceNetboxTenancyContactRoleUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactRoleUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.ContactRole{} @@ -219,26 +220,26 @@ func resourceNetboxTenancyContactRoleUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Tenancy.TenancyContactRolesPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxTenancyContactRoleRead(d, m) + return resourceNetboxTenancyContactRoleRead(ctx, d, m) } -func resourceNetboxTenancyContactRoleDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyContactRoleDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxTenancyContactRoleExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -247,12 +248,12 @@ func resourceNetboxTenancyContactRoleDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } p := tenancy.NewTenancyContactRolesDeleteParams().WithID(id) if _, err := client.Tenancy.TenancyContactRolesDelete(p, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_tenancy_tenant.go b/netbox/resource_netbox_tenancy_tenant.go index d0bb7bb59..269b661e3 100644 --- a/netbox/resource_netbox_tenancy_tenant.go +++ b/netbox/resource_netbox_tenancy_tenant.go @@ -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" @@ -14,12 +15,12 @@ import ( func resourceNetboxTenancyTenant() *schema.Resource { return &schema.Resource{ - Description: "Manage a tenant (tenancy module) within Netbox.", - Create: resourceNetboxTenancyTenantCreate, - Read: resourceNetboxTenancyTenantRead, - Update: resourceNetboxTenancyTenantUpdate, - Delete: resourceNetboxTenancyTenantDelete, - Exists: resourceNetboxTenancyTenantExists, + Description: "Manage a tenant (tenancy module) within Netbox.", + CreateContext: resourceNetboxTenancyTenantCreate, + ReadContext: resourceNetboxTenancyTenantRead, + UpdateContext: resourceNetboxTenancyTenantUpdate, + DeleteContext: resourceNetboxTenancyTenantDelete, + Exists: resourceNetboxTenancyTenantExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -112,8 +113,8 @@ func resourceNetboxTenancyTenant() *schema.Resource { } } -func resourceNetboxTenancyTenantCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) comments := d.Get("comments").(string) @@ -142,23 +143,23 @@ func resourceNetboxTenancyTenantCreate(d *schema.ResourceData, resourceCreated, err := client.Tenancy.TenancyTenantsCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxTenancyTenantRead(d, m) + return resourceNetboxTenancyTenantRead(ctx, d, m) } -func resourceNetboxTenancyTenantRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := tenancy.NewTenancyTenantsListParams().WithID(&resourceID) resources, err := client.Tenancy.TenancyTenantsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { @@ -172,18 +173,18 @@ func resourceNetboxTenancyTenantRead(d *schema.ResourceData, } if err = d.Set("comments", comments); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -194,29 +195,29 @@ func resourceNetboxTenancyTenantRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if resource.Group == nil { if err = d.Set("tenant_group_id", 0); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("tenant_group_id", resource.Group.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("slug", resource.Slug); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } return nil @@ -227,8 +228,8 @@ func resourceNetboxTenancyTenantRead(d *schema.ResourceData, return nil } -func resourceNetboxTenancyTenantUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableTenant{} @@ -273,26 +274,26 @@ func resourceNetboxTenancyTenantUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Tenancy.TenancyTenantsPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxTenancyTenantRead(d, m) + return resourceNetboxTenancyTenantRead(ctx, d, m) } -func resourceNetboxTenancyTenantDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxTenancyTenantExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -301,12 +302,12 @@ func resourceNetboxTenancyTenantDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } p := tenancy.NewTenancyTenantsDeleteParams().WithID(id) if _, err := client.Tenancy.TenancyTenantsDelete(p, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_tenancy_tenant_group.go b/netbox/resource_netbox_tenancy_tenant_group.go index 131dc3ee7..08cc106d4 100644 --- a/netbox/resource_netbox_tenancy_tenant_group.go +++ b/netbox/resource_netbox_tenancy_tenant_group.go @@ -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" @@ -14,12 +15,12 @@ import ( func resourceNetboxTenancyTenantGroup() *schema.Resource { return &schema.Resource{ - Description: "Manage a tenant group (tenancy module) within Netbox.", - Create: resourceNetboxTenancyTenantGroupCreate, - Read: resourceNetboxTenancyTenantGroupRead, - Update: resourceNetboxTenancyTenantGroupUpdate, - Delete: resourceNetboxTenancyTenantGroupDelete, - Exists: resourceNetboxTenancyTenantGroupExists, + Description: "Manage a tenant group (tenancy module) within Netbox.", + CreateContext: resourceNetboxTenancyTenantGroupCreate, + ReadContext: resourceNetboxTenancyTenantGroupRead, + UpdateContext: resourceNetboxTenancyTenantGroupUpdate, + DeleteContext: resourceNetboxTenancyTenantGroupDelete, + Exists: resourceNetboxTenancyTenantGroupExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -67,8 +68,8 @@ func resourceNetboxTenancyTenantGroup() *schema.Resource { } } -func resourceNetboxTenancyTenantGroupCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantGroupCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) groupName := d.Get("name").(string) @@ -85,41 +86,41 @@ func resourceNetboxTenancyTenantGroupCreate(d *schema.ResourceData, resourceCreated, err := client.Tenancy.TenancyTenantGroupsCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxTenancyTenantGroupRead(d, m) + return resourceNetboxTenancyTenantGroupRead(ctx, d, m) } -func resourceNetboxTenancyTenantGroupRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantGroupRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() params := tenancy.NewTenancyTenantGroupsListParams().WithID(&resourceID) resources, err := client.Tenancy.TenancyTenantGroupsList(params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("slug", resource.Slug); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } return nil @@ -131,8 +132,8 @@ func resourceNetboxTenancyTenantGroupRead(d *schema.ResourceData, return nil } -func resourceNetboxTenancyTenantGroupUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantGroupUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableTenantGroup{} @@ -151,26 +152,26 @@ func resourceNetboxTenancyTenantGroupUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) _, err = client.Tenancy.TenancyTenantGroupsPartialUpdate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxTenancyTenantGroupRead(d, m) + return resourceNetboxTenancyTenantGroupRead(ctx, d, m) } -func resourceNetboxTenancyTenantGroupDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxTenancyTenantGroupDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxTenancyTenantGroupExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -179,12 +180,12 @@ func resourceNetboxTenancyTenantGroupDelete(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert tenant ID into int64") + return diag.Errorf("Unable to convert tenant ID into int64") } resource := tenancy.NewTenancyTenantGroupsDeleteParams().WithID(resourceID) if _, err := client.Tenancy.TenancyTenantGroupsDelete(resource, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_virtualization_interface.go b/netbox/resource_netbox_virtualization_interface.go index d6e56ed64..b3759bdca 100644 --- a/netbox/resource_netbox_virtualization_interface.go +++ b/netbox/resource_netbox_virtualization_interface.go @@ -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" @@ -14,12 +15,12 @@ import ( func resourceNetboxVirtualizationInterface() *schema.Resource { return &schema.Resource{ - Description: "Manage an interface (virtualization module) resource within Netbox.", - Create: resourceNetboxVirtualizationInterfaceCreate, - Read: resourceNetboxVirtualizationInterfaceRead, - Update: resourceNetboxVirtualizationInterfaceUpdate, - Delete: resourceNetboxVirtualizationInterfaceDelete, - Exists: resourceNetboxVirtualizationInterfaceExists, + Description: "Manage an interface (virtualization module) resource within Netbox.", + CreateContext: resourceNetboxVirtualizationInterfaceCreate, + ReadContext: resourceNetboxVirtualizationInterfaceRead, + UpdateContext: resourceNetboxVirtualizationInterfaceUpdate, + DeleteContext: resourceNetboxVirtualizationInterfaceDelete, + Exists: resourceNetboxVirtualizationInterfaceExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -145,8 +146,8 @@ func resourceNetboxVirtualizationInterface() *schema.Resource { } } -func resourceNetboxVirtualizationInterfaceCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationInterfaceCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceCustomFields := d.Get("custom_field").(*schema.Set).List() @@ -191,16 +192,16 @@ func resourceNetboxVirtualizationInterfaceCreate(d *schema.ResourceData, resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxVirtualizationInterfaceRead(d, m) + return resourceNetboxVirtualizationInterfaceRead(ctx, d, m) } -func resourceNetboxVirtualizationInterfaceRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationInterfaceRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() @@ -210,20 +211,20 @@ func resourceNetboxVirtualizationInterfaceRead(d *schema.ResourceData, params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } var description interface{} @@ -234,61 +235,61 @@ func resourceNetboxVirtualizationInterfaceRead(d *schema.ResourceData, } if err = d.Set("description", description); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("enabled", resource.Enabled); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("mac_address", resource.MacAddress); err != nil { - return err + return diag.FromErr(err) } if resource.Mode == nil { if err = d.Set("mode", ""); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("mode", resource.Mode.Value); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("mtu", resource.Mtu); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tagged_vlans", resource.TaggedVlans); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags( resource.Tags)); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("untagged_vlan", resource.UntaggedVlan); err != nil { - return err + return diag.FromErr(err) } if resource.VirtualMachine == nil { if err = d.Set("virtualmachine_id", 0); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("virtualmachine_id", resource.VirtualMachine.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("type", VMInterfaceType); err != nil { - return err + return diag.FromErr(err) } return nil @@ -299,8 +300,8 @@ func resourceNetboxVirtualizationInterfaceRead(d *schema.ResourceData, return nil } -func resourceNetboxVirtualizationInterfaceUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationInterfaceUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableVMInterface{} @@ -358,7 +359,7 @@ func resourceNetboxVirtualizationInterfaceUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) @@ -366,19 +367,19 @@ func resourceNetboxVirtualizationInterfaceUpdate(d *schema.ResourceData, _, err = client.Virtualization.VirtualizationInterfacesPartialUpdate( resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxVirtualizationInterfaceRead(d, m) + return resourceNetboxVirtualizationInterfaceRead(ctx, d, m) } -func resourceNetboxVirtualizationInterfaceDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationInterfaceDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxVirtualizationInterfaceExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -387,13 +388,13 @@ func resourceNetboxVirtualizationInterfaceDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } p := virtualization.NewVirtualizationInterfacesDeleteParams().WithID(id) if _, err := client.Virtualization.VirtualizationInterfacesDelete( p, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/netbox/resource_netbox_virtualization_vm.go b/netbox/resource_netbox_virtualization_vm.go index da7a59c14..6918955a5 100644 --- a/netbox/resource_netbox_virtualization_vm.go +++ b/netbox/resource_netbox_virtualization_vm.go @@ -1,12 +1,14 @@ package netbox import ( + "context" "encoding/json" "fmt" "regexp" "strconv" "strings" + "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" @@ -16,12 +18,12 @@ import ( func resourceNetboxVirtualizationVM() *schema.Resource { return &schema.Resource{ - Description: "Manage a VM (virtualization module) resource within Netbox.", - Create: resourceNetboxVirtualizationVMCreate, - Read: resourceNetboxVirtualizationVMRead, - Update: resourceNetboxVirtualizationVMUpdate, - Delete: resourceNetboxVirtualizationVMDelete, - Exists: resourceNetboxVirtualizationVMExists, + Description: "Manage a VM (virtualization module) resource within Netbox.", + CreateContext: resourceNetboxVirtualizationVMCreate, + ReadContext: resourceNetboxVirtualizationVMRead, + UpdateContext: resourceNetboxVirtualizationVMUpdate, + DeleteContext: resourceNetboxVirtualizationVMDelete, + Exists: resourceNetboxVirtualizationVMExists, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -154,8 +156,8 @@ func resourceNetboxVirtualizationVM() *schema.Resource { } } -func resourceNetboxVirtualizationVMCreate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationVMCreate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) clusterID := int64(d.Get("cluster_id").(int)) @@ -197,7 +199,7 @@ func resourceNetboxVirtualizationVMCreate(d *schema.ResourceData, if localContextData != "" { var localContextDataMap map[string]*interface{} if err := json.Unmarshal([]byte(localContextData), &localContextDataMap); err != nil { - return err + return diag.FromErr(err) } newResource.LocalContextData = localContextDataMap } @@ -223,16 +225,16 @@ func resourceNetboxVirtualizationVMCreate(d *schema.ResourceData, resourceCreated, err := client.Virtualization.VirtualizationVirtualMachinesCreate(resource, nil) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.FormatInt(resourceCreated.Payload.ID, 10)) - return resourceNetboxVirtualizationVMRead(d, m) + return resourceNetboxVirtualizationVMRead(ctx, d, m) } -func resourceNetboxVirtualizationVMRead(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationVMRead(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceID := d.Id() @@ -242,13 +244,13 @@ func resourceNetboxVirtualizationVMRead(d *schema.ResourceData, params, nil) if err != nil { - return err + return diag.FromErr(err) } for _, resource := range resources.Payload.Results { if strconv.FormatInt(resource.ID, 10) == d.Id() { if err = d.Set("cluster_id", resource.Cluster.ID); err != nil { - return err + return diag.FromErr(err) } var comments interface{} @@ -259,85 +261,85 @@ func resourceNetboxVirtualizationVMRead(d *schema.ResourceData, } if err = d.Set("comments", comments); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("content_type", convertURIContentType(resource.URL)); err != nil { - return err + return diag.FromErr(err) } resourceCustomFields := d.Get("custom_field").(*schema.Set).List() customFields := updateCustomFieldsFromAPI(resourceCustomFields, resource.CustomFields) if err = d.Set("custom_field", customFields); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("disk", resource.Disk); err != nil { - return err + return diag.FromErr(err) } if resource.LocalContextData != nil { localContextDataJSON, err := json.Marshal(resource.LocalContextData) if err != nil { - return err + return diag.FromErr(err) } if err = d.Set("local_context_data", string(localContextDataJSON)); err != nil { - return err + return diag.FromErr(err) } } else { d.Set("local_context_data", "") } if err = d.Set("memory", resource.Memory); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("name", resource.Name); err != nil { - return err + return diag.FromErr(err) } if resource.Platform == nil { if err = d.Set("platform_id", 0); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("platform_id", resource.Platform.ID); err != nil { - return err + return diag.FromErr(err) } } if resource.Role == nil { if err = d.Set("role_id", 0); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("role_id", resource.Role.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("status", resource.Status.Value); err != nil { - return err + return diag.FromErr(err) } if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { - return err + return diag.FromErr(err) } if resource.Tenant == nil { if err = d.Set("tenant_id", 0); err != nil { - return err + return diag.FromErr(err) } } else { if err = d.Set("tenant_id", resource.Tenant.ID); err != nil { - return err + return diag.FromErr(err) } } if err = d.Set("vcpus", fmt.Sprintf("%v", *resource.Vcpus)); err != nil { - return err + return diag.FromErr(err) } return nil @@ -348,8 +350,8 @@ func resourceNetboxVirtualizationVMRead(d *schema.ResourceData, return nil } -func resourceNetboxVirtualizationVMUpdate(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationVMUpdate(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := &models.WritableVirtualMachineWithConfigContext{} @@ -384,7 +386,7 @@ func resourceNetboxVirtualizationVMUpdate(d *schema.ResourceData, if localContextData == "" { localContextDataMap = nil } else if err := json.Unmarshal([]byte(localContextData), &localContextDataMap); err != nil { - return err + return diag.FromErr(err) } params.LocalContextData = localContextDataMap } @@ -432,7 +434,7 @@ func resourceNetboxVirtualizationVMUpdate(d *schema.ResourceData, resourceID, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } resource.SetID(resourceID) @@ -440,19 +442,19 @@ func resourceNetboxVirtualizationVMUpdate(d *schema.ResourceData, _, err = client.Virtualization.VirtualizationVirtualMachinesPartialUpdate( resource, nil) if err != nil { - return err + return diag.FromErr(err) } - return resourceNetboxVirtualizationVMRead(d, m) + return resourceNetboxVirtualizationVMRead(ctx, d, m) } -func resourceNetboxVirtualizationVMDelete(d *schema.ResourceData, - m interface{}) error { +func resourceNetboxVirtualizationVMDelete(ctx context.Context, d *schema.ResourceData, + m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) resourceExists, err := resourceNetboxVirtualizationVMExists(d, m) if err != nil { - return err + return diag.FromErr(err) } if !resourceExists { @@ -461,13 +463,13 @@ func resourceNetboxVirtualizationVMDelete(d *schema.ResourceData, id, err := strconv.ParseInt(d.Id(), 10, 64) if err != nil { - return fmt.Errorf("Unable to convert ID into int64") + return diag.Errorf("Unable to convert ID into int64") } p := virtualization.NewVirtualizationVirtualMachinesDeleteParams().WithID(id) if _, err := client.Virtualization.VirtualizationVirtualMachinesDelete( p, nil); err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/utils/generateJsonDatasources b/utils/generateJsonDatasources index caeb93bfc..5e7c43c9b 100755 --- a/utils/generateJsonDatasources +++ b/utils/generateJsonDatasources @@ -94,7 +94,7 @@ import ( func dataNetboxJSON${SECTION}${ITEM}List() *schema.Resource { return &schema.Resource{ Description: "Get json output from the ${ENDPOINT}_list Netbox endpoint.", - Read: dataNetboxJSON${SECTION}${ITEM}ListRead, + ReadContext: dataNetboxJSON${SECTION}${ITEM}ListRead, Schema: map[string]*schema.Schema{ "limit": { @@ -112,7 +112,7 @@ func dataNetboxJSON${SECTION}${ITEM}List() *schema.Resource { } } -func dataNetboxJSON${SECTION}${ITEM}ListRead(d *schema.ResourceData, m interface{}) error { +func dataNetboxJSON${SECTION}${ITEM}ListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*netboxclient.NetBoxAPI) params := ${SECTION,}.New${SECTION}${ITEM}ListParams() @@ -121,7 +121,7 @@ func dataNetboxJSON${SECTION}${ITEM}ListRead(d *schema.ResourceData, m interface list, err := client.${SECTION}.${SECTION}${ITEM}List(params, nil) if err != nil { - return err + return diag.FromErr(err) } j, _ := json.Marshal(list.Payload.Results)