smutel / terraform-provider-netbox

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

feat: Update to work with Netbox 3.3 #172

Closed smutel closed 1 year ago

smutel commented 1 year ago

Hello @amhn,

I would like to update all go deps (including go-netbox). Previously I did it with the makefile:

update-go-deps:
    @echo "==> Updating Go dependencies"
    go get -u -d $$(pwd)
    go mod tidy
    go mod vendor

It seems that it does not work anymore. If I use these command, the folder vendor is removed and go.mod is emptying. Did you change something there around this ?

amhn commented 1 year ago

Works for me. Do you get any errors when you run update-go-deps?

$ make update-go-deps
==> Updating Go dependencies
go get -u -d $(pwd)
go: added github.com/go-logr/logr v1.2.3
go: added github.com/go-logr/stdr v1.2.2
go: upgraded github.com/go-openapi/jsonpointer v0.19.5 => v0.19.6
go: upgraded github.com/go-openapi/jsonreference v0.20.0 => v0.20.1
go: upgraded github.com/go-openapi/runtime v0.24.2 => v0.25.0
go: upgraded github.com/hashicorp/go-hclog v1.3.1 => v1.4.0
go: upgraded github.com/hashicorp/go-plugin v1.4.6 => v1.4.8
go: upgraded github.com/hashicorp/terraform-plugin-go v0.14.1 => v0.14.3
go: upgraded github.com/mattn/go-isatty v0.0.16 => v0.0.17
go: upgraded github.com/smutel/go-netbox/v3 v3.2.3 => v3.3.0
go: upgraded go.mongodb.org/mongo-driver v1.11.0 => v1.11.1
go: added go.opentelemetry.io/otel v1.11.2
go: added go.opentelemetry.io/otel/trace v1.11.2
go: upgraded golang.org/x/crypto v0.2.0 => v0.5.0
go: upgraded golang.org/x/net v0.2.0 => v0.5.0
go: upgraded golang.org/x/sys v0.2.0 => v0.4.0
go: upgraded golang.org/x/text v0.4.0 => v0.6.0
go: upgraded google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 => v0.0.0-20230110181048-76db0878b65f
go: upgraded google.golang.org/grpc v1.50.1 => v1.52.0
go mod tidy
go mod vendor
amhn commented 1 year ago

The following fixes the build error after updating the dependencies:

diff --git a/netbox/ipam/util.go b/netbox/ipam/util.go
index e93e108f..c3b0d0b2 100644
--- a/netbox/ipam/util.go
+++ b/netbox/ipam/util.go
@@ -40,8 +40,11 @@ func getNewAvailableIPForPrefix(client *netboxclient.NetBoxAPI, id int64) (*mode

 func getNewAvailablePrefix(client *netboxclient.NetBoxAPI, id int64, length int64) (*models.Prefix, error) {
        params := ipam.NewIpamPrefixesAvailablePrefixesCreateParams().WithID(id)
-       params.Data = &models.PrefixLength{}
-       params.Data.PrefixLength = &length
+       params.Data = []*models.PrefixLength{
+               {
+                       PrefixLength: &length,
+               },
+       }
        list, err := client.Ipam.IpamPrefixesAvailablePrefixesCreate(params, nil)
        if err != nil {
                return nil, err
amhn commented 1 year ago

The following diff fixes the test failures with dcim_site:

diff --git a/netbox/dcim/resource_netbox_dcim_site.go b/netbox/dcim/resource_netbox_dcim_site.go
index f2c86752..0a0e65dc 100644
--- a/netbox/dcim/resource_netbox_dcim_site.go
+++ b/netbox/dcim/resource_netbox_dcim_site.go
@@ -198,7 +198,6 @@ func resourceNetboxDcimSiteCreate(ctx context.Context, d *schema.ResourceData,
        slug := d.Get("slug").(string)
        tags := d.Get("tag").(*schema.Set).List()
        tenantID := int64(d.Get("tenant_id").(int))
-       timezone := d.Get("time_zone").(string)

        newResource := &models.WritableSite{
                Asns:            util.ToListofInts(asns),
@@ -214,7 +213,6 @@ func resourceNetboxDcimSiteCreate(ctx context.Context, d *schema.ResourceData,
                Slug:            &slug,
                Status:          d.Get("status").(string),
                Tags:            tag.ConvertTagsToNestedTags(tags),
-               TimeZone:        &timezone,
        }

        if groupID != 0 {
@@ -226,6 +224,9 @@ func resourceNetboxDcimSiteCreate(ctx context.Context, d *schema.ResourceData,
        if tenantID != 0 {
                newResource.Tenant = &tenantID
        }
+       if timezone := d.Get("time_zone").(string); timezone != "" {
+               newResource.TimeZone = &timezone
+       }

        resource := dcim.NewDcimSitesCreateParams().WithData(newResource)
smutel commented 1 year ago

Thank you for the fixes. My MR was not up to date.

For the go mod, I found the issue. I cloned my repo and yours and I did a symlink but it seems that go mod does not like symlink.