netbox_ip_address does not set virtualization.vminterface value correctly #7606

Closed
opened 2025-12-29 20:26:01 +01:00 by adam · 2 comments
Owner

Originally created by @vitaliyboch on GitHub (Feb 6, 2023).

NetBox version

3.0.13

Python version

3.8

Steps to Reproduce

  1. Assign an ip address from a physical server:
resource "netbox_device_role" "hypervisor" {
  name      = "Hypervisor"
  slug      = "hypervisor"
  color_hex = "808080"  #gray
}

resource "netbox_manufacturer" "dell" {
  name = "Dell"
  slug = "dell"
}

resource "netbox_device_type" "server_dell" {
  model           = "PowerEdge R440"
  slug            = "poweredge-r440"
  manufacturer_id = netbox_manufacturer.dell.id
}

resource "netbox_device" "pyshical_server" {
  name           = "pyshical_server"
  device_type_id = netbox_device_type.server_dell.id
  role_id        = netbox_device_role.hypervisor.id
  site_id        = netbox_site.stack24_kazan.id
}

resource "netbox_device_interface" "pyshical_server_nic" {
  name        = "pyshical_server"
  type        = "1000base-kx"
  device_id   = netbox_device.pyshical_server.id
}

resource "netbox_ip_address" "pyshical_server_ip" {
  ip_address   = "10.70.23.2/25"
  status       = "active"
  dns_name     = "pyshical_server"
  interface_id = netbox_device_interface.pyshical_server_nic.id
}
  1. Open the netbox portal at https://netbox_server/ipam/ip-addresses/ and get the error:
Server Error
There was a problem with your request. Please contact an administrator.

The complete exception is provided below:

<class 'AttributeError'>

'NoneType' object has no attribute 'get_absolute_url'

Python version: 3.8.10
NetBox version: 3.4.4
If further assistance is required, please post to the [NetBox discussion forum](https://github.com/netbox-community/netbox/discussions) on GitHub.
  1. Check the API results at https://netbox_server/api/ipam/ip-addresses/
  2. Comment interface_id = netbox_device_interface.pyshical_server_nic.id in the code and apply the code again. The issue is gone.

Analysys:
The issue is in missing attribute assigned_object_type": "dcim.interface when the terraform plugin applies the code. By default the attribute equals "virtualization.vminterface".

These are fragments of API replies of implemeting physical interface assigment via the plugin and via the web-interface:

not assigned:

        {
            "id": 8,
            "url": "https://10.70.23.31/api/ipam/ip-addresses/8/",
            "display": "10.70.23.1/25",
            "family": {
                "value": 4,
                "label": "IPv4"
            },
            "address": "10.70.23.1/25",
            "vrf": null,
            "tenant": null,
            "status": {
                "value": "active",
                "label": "Active"
            },
            "role": null,
            "assigned_object_type": null,
            "assigned_object_id": null,
            "assigned_object": null,
            "nat_inside": null,
            "nat_outside": [],
            "comments": "",
            "tags": [],
            "custom_fields": {},
            "created": "2023-02-06T15:17:07.330362Z",
            "last_updated": "2023-02-06T15:56:00.283768Z"
        }

wrong:

        {
            "id": 8,
            "url": "https://10.70.23.31/api/ipam/ip-addresses/8/",
            "display": "10.70.23.1/25",
            "family": {
                "value": 4,
                "label": "IPv4"
            },
            "address": "10.70.23.1/25",
            "vrf": null,
            "tenant": null,
            "status": {
                "value": "active",
                "label": "Active"
            },
            "role": null,
            "assigned_object_type": "virtualization.vminterface",     <<<==== wrong type
            "assigned_object_id": 4,
            "assigned_object": {                                      <<<==== got wrong interface description by id from VM table
                "id": 4,
                "url": "https://10.70.23.31/api/virtualization/interfaces/4/",
                "display": "netbox-nic0",
                "virtual_machine": {
                    "id": 5,
                    "url": "https://10.70.23.31/api/virtualization/virtual-machines/5/",
                    "display": "netbox",
                    "name": "netbox"
                },
                "name": "netbox-nic0"
            },
            "nat_inside": null,
            "nat_outside": [],
            "dns_name": "osp-kvm-01",
            "comments": "",
            "tags": [],
            "custom_fields": {},
            "created": "2023-02-06T15:17:07.330362Z",
            "last_updated": "2023-02-06T15:57:30.014865Z"
        }

correct:

        {
            "id": 8,
            "url": "https://10.70.23.31/api/ipam/ip-addresses/8/",
            "display": "10.70.23.1/25",
            "family": {
                "value": 4,
                "label": "IPv4"
            },
            "address": "10.70.23.1/25",
            "vrf": null,
            "tenant": null,
            "status": {
                "value": "active",
                "label": "Active"
            },
            "role": null,
            "assigned_object_type": "dcim.interface",     <<<==== correct type
            "assigned_object_id": 4,
            "assigned_object": {                                      <<<==== got corect interface description by id from DEVICES table
                "id": 4,
                "url": "https://10.70.23.31/api/dcim/interfaces/4/",
                "display": "osp-kvm-01-management",
                "device": {
                    "id": 5,
                    "url": "https://10.70.23.31/api/dcim/devices/5/",
                    "display": "osp-kvm-01",
                    "name": "osp-kvm-01"
                },
                "name": "osp-kvm-01-management",
                "cable": null,
                "_occupied": false
            },
            "nat_inside": null,
            "nat_outside": [],
            "dns_name": "osp-kvm-01",
            "comments": "",
            "tags": [],
            "custom_fields": {},
            "created": "2023-02-06T15:17:07.330362Z",
            "last_updated": "2023-02-06T16:00:29.262894Z"
        }

Expected Behavior

netbox_ip_address command should be able to detect or manually set type of assinned resources

Observed Behavior

netbox_ip_address command always set "assigned_object_type": "virtualization.vminterface" be able to detect or manually set type of assinned resources

Originally created by @vitaliyboch on GitHub (Feb 6, 2023). ### NetBox version 3.0.13 ### Python version 3.8 ### Steps to Reproduce 1. Assign an ip address from a physical server: ``` resource "netbox_device_role" "hypervisor" { name = "Hypervisor" slug = "hypervisor" color_hex = "808080" #gray } resource "netbox_manufacturer" "dell" { name = "Dell" slug = "dell" } resource "netbox_device_type" "server_dell" { model = "PowerEdge R440" slug = "poweredge-r440" manufacturer_id = netbox_manufacturer.dell.id } resource "netbox_device" "pyshical_server" { name = "pyshical_server" device_type_id = netbox_device_type.server_dell.id role_id = netbox_device_role.hypervisor.id site_id = netbox_site.stack24_kazan.id } resource "netbox_device_interface" "pyshical_server_nic" { name = "pyshical_server" type = "1000base-kx" device_id = netbox_device.pyshical_server.id } resource "netbox_ip_address" "pyshical_server_ip" { ip_address = "10.70.23.2/25" status = "active" dns_name = "pyshical_server" interface_id = netbox_device_interface.pyshical_server_nic.id } ``` 2. Open the netbox portal at https://netbox_server/ipam/ip-addresses/ and get the error: ``` Server Error There was a problem with your request. Please contact an administrator. The complete exception is provided below: <class 'AttributeError'> 'NoneType' object has no attribute 'get_absolute_url' Python version: 3.8.10 NetBox version: 3.4.4 If further assistance is required, please post to the [NetBox discussion forum](https://github.com/netbox-community/netbox/discussions) on GitHub. ``` 3. Check the API results at https://netbox_server/api/ipam/ip-addresses/ 4. Comment `interface_id = netbox_device_interface.pyshical_server_nic.id` in the code and apply the code again. The issue is gone. **Analysys:** The issue is in missing attribute `assigned_object_type": "dcim.interface` when the terraform plugin applies the code. By default the attribute equals `"virtualization.vminterface"`. These are fragments of API replies of implemeting physical interface assigment via the plugin and via the web-interface: not assigned: ``` { "id": 8, "url": "https://10.70.23.31/api/ipam/ip-addresses/8/", "display": "10.70.23.1/25", "family": { "value": 4, "label": "IPv4" }, "address": "10.70.23.1/25", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": null, "assigned_object_id": null, "assigned_object": null, "nat_inside": null, "nat_outside": [], "comments": "", "tags": [], "custom_fields": {}, "created": "2023-02-06T15:17:07.330362Z", "last_updated": "2023-02-06T15:56:00.283768Z" } ``` wrong: ``` { "id": 8, "url": "https://10.70.23.31/api/ipam/ip-addresses/8/", "display": "10.70.23.1/25", "family": { "value": 4, "label": "IPv4" }, "address": "10.70.23.1/25", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": "virtualization.vminterface", <<<==== wrong type "assigned_object_id": 4, "assigned_object": { <<<==== got wrong interface description by id from VM table "id": 4, "url": "https://10.70.23.31/api/virtualization/interfaces/4/", "display": "netbox-nic0", "virtual_machine": { "id": 5, "url": "https://10.70.23.31/api/virtualization/virtual-machines/5/", "display": "netbox", "name": "netbox" }, "name": "netbox-nic0" }, "nat_inside": null, "nat_outside": [], "dns_name": "osp-kvm-01", "comments": "", "tags": [], "custom_fields": {}, "created": "2023-02-06T15:17:07.330362Z", "last_updated": "2023-02-06T15:57:30.014865Z" } ``` correct: ``` { "id": 8, "url": "https://10.70.23.31/api/ipam/ip-addresses/8/", "display": "10.70.23.1/25", "family": { "value": 4, "label": "IPv4" }, "address": "10.70.23.1/25", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": "dcim.interface", <<<==== correct type "assigned_object_id": 4, "assigned_object": { <<<==== got corect interface description by id from DEVICES table "id": 4, "url": "https://10.70.23.31/api/dcim/interfaces/4/", "display": "osp-kvm-01-management", "device": { "id": 5, "url": "https://10.70.23.31/api/dcim/devices/5/", "display": "osp-kvm-01", "name": "osp-kvm-01" }, "name": "osp-kvm-01-management", "cable": null, "_occupied": false }, "nat_inside": null, "nat_outside": [], "dns_name": "osp-kvm-01", "comments": "", "tags": [], "custom_fields": {}, "created": "2023-02-06T15:17:07.330362Z", "last_updated": "2023-02-06T16:00:29.262894Z" } ``` ### Expected Behavior `netbox_ip_address` command should be able to detect or manually set type of assinned resources ### Observed Behavior `netbox_ip_address` command always set `"assigned_object_type": "virtualization.vminterface"` be able to detect or manually set type of assinned resources
adam closed this issue 2025-12-29 20:26:01 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 6, 2023):

This repo is for the core NetBox project. If you have an issue using a specific Terraform provider, please submit a bug report to that project.

@jeremystretch commented on GitHub (Feb 6, 2023): This repo is for the core NetBox project. If you have an issue using a specific Terraform provider, please submit a bug report to that project.
Author
Owner

@vitaliyboch commented on GitHub (Feb 6, 2023):

You are right, the topic is about the terrafrom provider.
The ticket has been copied to https://github.com/e-breuninger/terraform-provider-netbox/issues/334

@vitaliyboch commented on GitHub (Feb 6, 2023): You are right, the topic is about the terrafrom provider. The ticket has been copied to https://github.com/e-breuninger/terraform-provider-netbox/issues/334
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7606