smutel / terraform-provider-netbox

Terraform provider for Netbox
ISC License
58 stars 19 forks source link

fix: Replace deprecated functions with context aware functions #136

Closed amhn closed 2 years ago

amhn commented 2 years ago

Fixes: #135

This PR is a simple search and replace. Deprecated fields are replaced and functions are updated to new signatures.

The following replacements were done: (Read,Create,Update,Delete) -> (Read,Create,Update,Delete)Context return err -> return diag.FromErr(err) fmt.Errrorf -> diag.Errorf error -> diag.Diagnostics in the relevant functions Add ctx context.Context to function signatures

TODO: Remove deprecated Exists-Functions and update Read-Function to use d.SetId("") if the resource does not exist. This needs proper error handling in go-netbox, which depends on https://github.com/netbox-community/netbox/issues/4986

smutel commented 2 years ago

I don't why the CI is not happy with your MR because you just replace some words and not add so much lines. Are you able to change the code to resolve this issue:

netbox/resource_netbox_ipam_ip_addresses.go:232:1: cyclomatic complexity 40 of func `resourceNetboxIpamIPAddressesRead` is high (> 30) (gocyclo)
  func resourceNetboxIpamIPAddressesRead(ctx context.Context, d *schema.ResourceData,
amhn commented 2 years ago

This is an issue with the existing function. In other PRs this is ignored, because the function is unchanged.

See for example PR #208:

  level=warning msg="[linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649."
  netbox/resource_netbox_ipam_ip_addresses.go:231:1: cyclomatic complexity 40 of func `resourceNetboxIpamIPAddressesRead` is high (> 30) (gocyclo)
  func resourceNetboxIpamIPAddressesRead(d *schema.ResourceData,
  ^
  /home/runner/work/_temp/reviewdog-JPDuAj/reviewdog -f=golangci-lint -name=golangci -reporter=github-pr-check -filter-mode=added -fail-on-error=true -level=error

I could revert the function in this PR. Or maybe switching from client.Ipam.IpamIPAddressesList to IpamIPAddressesRead and removing the Loop reduces the complexity enough to pass linting.

I can look into it. But I would prefer if this PR only migrates the deprecated functions to the new ones.