Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] VM Type int64 Netbox v4.0.2 #598

Closed
ThorstenFR-Cyber opened this issue May 19, 2024 · 19 comments · Fixed by fbreckle/go-netbox#41
Closed

[BUG] VM Type int64 Netbox v4.0.2 #598

ThorstenFR-Cyber opened this issue May 19, 2024 · 19 comments · Fixed by fbreckle/go-netbox#41

Comments

@ThorstenFR-Cyber
Copy link

Issue Reporting Guide

Hi there,

I can't retrieve information about VMs in Netbox using Terraform. I'm encountering an error related to type int64. I have checked the code, but I couldn't find NestedIPAddress.results.primary_ip.family. If you can help, that would be great.

Netbox Version

V4.0.2

Terraform Version

Terraform v1.7.4
on linux_amd64

  • provider registry.terraform.io/bpg/proxmox v0.57.0
  • provider registry.terraform.io/e-breuninger/netbox v3.8.6
  • provider registry.terraform.io/hashicorp/random v3.6.1
  • provider registry.terraform.io/hashicorp/tls v4.0.5

Affected Resource(s)

  • netbox_virtual_machines

Debug Output

https://gist.github.com/ThorstenFR-Cyber/6a60d4dd9a039953bb8ab1b055a9fffe

Expected Behavior

data "netbox_interfaces" "net0" {
  name_regex = "net0"
  filter {
    name  = "vm_id"
    value = "20"
  }
}


data "netbox_virtual_machines" "base_vm" {
  name_regex = "GIT"
  filter {
    name  = "cluster_id"
    value = data.netbox_cluster.vmw_cluster_01.id
  }
}
@fbreckle
Copy link
Collaborator

I get this error when I run the current test suite against netbox 4.0.2 as well, so I figure this is caused by a change made in netbox 4.0.

ATM, the provider does not support netbox 4.0. This will be next up once we have some of the recent PRs merged.

@ThorstenFR-Cyber
Copy link
Author

I may have found the problem. It comes from a repository https://github.com/fbreckle/go-netbox that defines the structure of the requests, specifically in the nested_ip_address.go file. It is necessary to change the NestedIPAddress structure from:

type NestedIPAddress struct {
    // Address
    //
    // IPv4 or IPv6 address (with mask)
    // Required: true
    Address *string `json:"address"`

    // Display
    // Read Only: true
    Display string `json:"display,omitempty"`

    // Family
    // Read Only: true
    Family int64 `json:"family,omitempty"`

    // ID
    // Read Only: true
    ID int64 `json:"id,omitempty"`

    // Url
    // Read Only: true
    // Format: uri
    URL strfmt.URI `json:"url,omitempty"`
}

to:

type NestedIPAddress struct {
    // Address
    //
    // IPv4 or IPv6 address (with mask)
    // Required: true
    Address *string `json:"address"`

    // Display
    // Read Only: true
    Display string `json:"display,omitempty"`

    // Family
    // Read Only: true
    Family struct {
        ID    int64  `json:"id"`
        Label string `json:"label"`
    } `json:"family,omitempty"`

    // ID
    // Read Only: true
    ID int64 `json:"id,omitempty"`

    // Url
    // Read Only: true
    // Format: uri
    URL strfmt.URI `json:"url,omitempty"`
}

I will test this change over the weekend to see if it fixes the problem and does not impact the older versions of NetBox.

@fbreckle
Copy link
Collaborator

Well, yeah, that is my dedicated library to support this provider. Naturally, it will need to be adjusted for netbox 4.0.

Changing the type of the Family field will lead to unmarshalling errors in older versions, I suppose.

@ignatenkobrain
Copy link

@fbreckle any chance to get this somehow fixed? 4.x is already out for quite some time…

@ThorstenFR-Cyber
Copy link
Author

No, it won't be fixed right away. I haven't resolved the issues yet because it's not just this function that's impacted. Additionally, after my modifications, the old versions of Netbox won't work anymore. He wants to merge all the PRs before patching for version 4.x.

@fbreckle
Copy link
Collaborator

fbreckle commented Jun 6, 2024

Basically, yes.

Since 4.0 support will break 3.x versions, I prefer to get features merged right now, release a final 3.x provider version (including the new features) and THEN do the 4.0 upgrade.

Plus just got out of Pentecost, which has impacted the time I had to work on this provider.

@mdepedrof
Copy link

Any update about this? I have the same error.

Thanks for your effort and your work

@peterbaumert
Copy link

Do you have any eta on this @fbreckle ? :)

@mraerino
Copy link
Contributor

i wonder if we could use different versions of the library depending on the Netbox version. if there is a new major of the api lib, you can use both at the same time in a Go project

@mraerino
Copy link
Contributor

i have a (very rough) PoC here for making the provider work with both 3.7 and 4.0: ffddorf#1

the test suite passes both on 3.7.8 and 4.0.7

@fbreckle is this a direction you'd see the provider adopting? if yes, i'll spend some time to polish it into a proper PR

@zeridon
Copy link

zeridon commented Aug 7, 2024

We are also affected but unfortunately there is no easy path backwards for us.

Wouldn't it be better to implement wrapped client using different libs depending on version of netbox api? (not that i am skilled enough to implement it)

@fbreckle
Copy link
Collaborator

fbreckle commented Aug 7, 2024

i have a (very rough) PoC here for making the provider work with both 3.7 and 4.0: ffddorf#1

the test suite passes both on 3.7.8 and 4.0.7

@fbreckle is this a direction you'd see the provider adopting? if yes, i'll spend some time to polish it into a proper PR

I feel that this will massively bloat the provider over time. Consider what happens when completely new resources arrive, attributes get changed etc.

My gut tells me to stick to the current approach of supporting the latest version (and yes, I know we're way behind on that).

@mraerino
Copy link
Contributor

mraerino commented Aug 7, 2024

so it might make more sense if i just put up a PR to support 4.x?

@fbreckle
Copy link
Collaborator

fbreckle commented Aug 8, 2024

so it might make more sense if i just put up a PR to support 4.x?

I went ahead and implemented everything in feature/netbox-4.0.

HOWEVER I basically took your implementation and removed the version switches, so I absolutely want to encourage you to make your own commits and PR so you get the credit. I just had to see it work myself first.

@zeridon
Copy link

zeridon commented Aug 8, 2024

I went ahead and implemented everything in feature/netbox-4.0.

The one comment from me is probably is best to bump the version to 4 as to be more aligned with netbox and signify that breakage will occur.

Will try to test it tomorrow

@fbreckle
Copy link
Collaborator

fbreckle commented Aug 8, 2024

Nah, if we match the major version of netbox, we will have the same problem when breaking changes in the provider occur.

The big things to do are custom fields and generalized data source parameters. I want to use major versions for these.

@mraerino
Copy link
Contributor

mraerino commented Aug 8, 2024

I basically took your implementation and removed the version switches, so I absolutely want to encourage you to make your own commits and PR so you get the credit

no worries, that's not a big deal.

if you want you can throw a Co-authored-by: mraerino <[email protected]> into the merge commit

just happy to see progress on the 4.x support

@zeridon
Copy link

zeridon commented Aug 9, 2024

I went ahead and implemented everything in feature/netbox-4.0.

The one comment from me is probably is best to bump the version to 4 as to be more aligned with netbox and signify that breakage will occur.

Will try to test it tomorrow

At least for my use case (vm, addr, interface, primary ip of the vm) works.

Just it complains that it is not compatible with the version of netbox ( https://github.com/e-breuninger/terraform-provider-netbox/blob/feature/netbox-4.0/netbox/provider.go#L298 )

@fbreckle
Copy link
Collaborator

fbreckle commented Aug 9, 2024

Oh, absolutely. I'll fix that and release later today.

@fbreckle fbreckle closed this as completed Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants