e-breuninger / terraform-provider-netbox

Terraform provider to interact with Netbox
https://registry.terraform.io/providers/e-breuninger/netbox/latest/docs
Mozilla Public License 2.0
172 stars 117 forks source link

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

Open ThorstenFR-Cyber opened 1 month ago

ThorstenFR-Cyber commented 1 month ago

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

Affected Resource(s)

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

ThorstenFR-Cyber commented 1 month ago

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 commented 1 month ago

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 commented 4 days ago

Any update about this? I have the same error.

Thanks for your effort and your work