Prefixes - Wrong depth #10768

Closed
opened 2025-12-29 21:35:45 +01:00 by adam · 3 comments
Owner

Originally created by @rybakovanton-metta on GitHub (Feb 13, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.2.3

Python Version

3.10

Steps to Reproduce

I creating prefixes via terraform

variable "networks" {
  type = list(object({
    cloud  = string
    prefix = string
    labels = list(string)
    status = optional(string)
  }))
}
resource "netbox_prefix" "tens" {
  prefix    = "10.0.0.0/8"
  status    = "container"
  tenant_id = var.tenant_id
  vrf_id    = var.vrf_id
  tags = [upper(var.environment)]
}

resource "netbox_prefix" "network" {
  for_each = {
    for k, v in var.networks : k => v
  }
  prefix    = each.value.prefix
  status    = each.value.status != null ?  each.value.status : "active"
  tenant_id = var.tenant_id
  vrf_id    = var.vrf_id
  tags      = each.value.cloud == null ? concat([upper(var.environment)], each.value.labels) : concat([upper(each.value.cloud), upper(var.environment)], each.value.labels)
}
config inside
    "networks": [
        {
            "prefix": "10.128.0.0/10",
            "labels": [
                "INFRA"
            ],
            "status": "container"
        },
        {
            "cloud":"aws",
            "prefix": "10.128.0.0/24",
            "labels": [
                "PUBLIC"
            ]
        },
        {
            "cloud":"azr",
            "prefix": "10.128.1.0/24",
            "labels": [
                "PUBLIC"
            ]
        },
        {
            "cloud":"gcp",
            "prefix": "10.128.2.0/24",
            "labels": [
                "PUBLIC"
            ]
        }
    ]

Expected Behavior

Prefixes created
Container 10/8 have depth = 0
Container 10.128.0.0/10 have depth = 1
Prefixes (10.128.0.0/24, 10.128.1.0/24, 10.128.2.0/24) have the same depth = 2
Children count have a corresponding value.

Observed Behavior

"random" depth
one example
Image

another one

Image
as you can see below, same thing in output fro rest request (_depth attribute)
{
    "id": 1196,
    "url": "https://192.168.1.82:9443/api/ipam/prefixes/1196/",
    "display_url": "https://192.168.1.82:9443/ipam/prefixes/1196/",
    "display": "10.0.0.0/8",
    "family": {
        "value": 4,
        "label": "IPv4"
    },
    "prefix": "10.0.0.0/8",
    "vrf": {
        "id": 6,
        "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/",
        "display": "devnet-infra_v3.3",
        "name": "devnet-infra_v3.3",
        "rd": null,
        "description": ""
    },
    "scope_type": null,
    "scope_id": null,
    "scope": null,
    "tenant": {
        "id": 2,
        "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/",
        "display": "DEVNET",
        "name": "DEVNET",
        "slug": "devnet",
        "description": "This is the environment for network development"
    },
    "vlan": null,
    "status": {
        "value": "container",
        "label": "Container"
    },
    "role": null,
    "is_pool": false,
    "mark_utilized": false,
    "description": "",
    "comments": "",
    "tags": [
        {
            "id": 13,
            "url": "https://192.168.1.82:9443/api/extras/tags/13/",
            "display_url": "https://192.168.1.82:9443/extras/tags/13/",
            "display": "DEVNET",
            "name": "DEVNET",
            "slug": "devnet",
            "color": "ff5722"
        }
    ],
    "custom_fields": {},
    "created": "2025-02-12T17:07:02.035430Z",
    "last_updated": "2025-02-12T17:07:02.035438Z",
    "children": 4,
    "_depth": 0
},
{
    "id": 1198,
    "url": "https://192.168.1.82:9443/api/ipam/prefixes/1198/",
    "display_url": "https://192.168.1.82:9443/ipam/prefixes/1198/",
    "display": "10.128.0.0/10",
    "family": {
        "value": 4,
        "label": "IPv4"
    },
    "prefix": "10.128.0.0/10",
    "vrf": {
        "id": 6,
        "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/",
        "display": "devnet-infra_v3.3",
        "name": "devnet-infra_v3.3",
        "rd": null,
        "description": ""
    },
    "scope_type": null,
    "scope_id": null,
    "scope": null,
    "tenant": {
        "id": 2,
        "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/",
        "display": "DEVNET",
        "name": "DEVNET",
        "slug": "devnet",
        "description": "This is the environment for network development"
    },
    "vlan": null,
    "status": {
        "value": "container",
        "label": "Container"
    },
    "role": null,
    "is_pool": false,
    "mark_utilized": false,
    "description": "",
    "comments": "",
    "tags": [
        {
            "id": 13,
            "url": "https://192.168.1.82:9443/api/extras/tags/13/",
            "display_url": "https://192.168.1.82:9443/extras/tags/13/",
            "display": "DEVNET",
            "name": "DEVNET",
            "slug": "devnet",
            "color": "ff5722"
        }
    ],
    "custom_fields": {},
    "created": "2025-02-12T17:07:02.078119Z",
    "last_updated": "2025-02-12T17:07:02.078126Z",
    "children": 3,
    "_depth": 0
},
{
    "id": 1204,
    "url": "https://192.168.1.82:9443/api/ipam/prefixes/1204/",
    "display_url": "https://192.168.1.82:9443/ipam/prefixes/1204/",
    "display": "10.128.0.0/24",
    "family": {
        "value": 4,
        "label": "IPv4"
    },
    "prefix": "10.128.0.0/24",
    "vrf": {
        "id": 6,
        "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/",
        "display": "devnet-infra_v3.3",
        "name": "devnet-infra_v3.3",
        "rd": null,
        "description": ""
    },
    "scope_type": null,
    "scope_id": null,
    "scope": null,
    "tenant": {
        "id": 2,
        "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/",
        "display": "DEVNET",
        "name": "DEVNET",
        "slug": "devnet",
        "description": "This is the environment for network development"
    },
    "vlan": null,
    "status": {
        "value": "active",
        "label": "Active"
    },
    "role": null,
    "is_pool": false,
    "mark_utilized": false,
    "description": "",
    "comments": "",
    "tags": [
        {
            "id": 3,
            "url": "https://192.168.1.82:9443/api/extras/tags/3/",
            "display_url": "https://192.168.1.82:9443/extras/tags/3/",
            "display": "AWS",
            "name": "AWS",
            "slug": "aws",
            "color": "ffe4e1"
        },
        {
            "id": 13,
            "url": "https://192.168.1.82:9443/api/extras/tags/13/",
            "display_url": "https://192.168.1.82:9443/extras/tags/13/",
            "display": "DEVNET",
            "name": "DEVNET",
            "slug": "devnet",
            "color": "ff5722"
        },
        {
            "id": 12,
            "url": "https://192.168.1.82:9443/api/extras/tags/12/",
            "display_url": "https://192.168.1.82:9443/extras/tags/12/",
            "display": "PUBLIC",
            "name": "PUBLIC",
            "slug": "public",
            "color": "607d8b"
        }
    ],
    "custom_fields": {},
    "created": "2025-02-12T17:34:26.645054Z",
    "last_updated": "2025-02-12T17:34:26.645059Z",
    "children": 0,
    "_depth": 2
},
{
    "id": 1197,
    "url": "https://192.168.1.82:9443/api/ipam/prefixes/1197/",
    "display_url": "https://192.168.1.82:9443/ipam/prefixes/1197/",
    "display": "10.128.1.0/24",
    "family": {
        "value": 4,
        "label": "IPv4"
    },
    "prefix": "10.128.1.0/24",
    "vrf": {
        "id": 6,
        "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/",
        "display": "devnet-infra_v3.3",
        "name": "devnet-infra_v3.3",
        "rd": null,
        "description": ""
    },
    "scope_type": null,
    "scope_id": null,
    "scope": null,
    "tenant": {
        "id": 2,
        "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/",
        "display": "DEVNET",
        "name": "DEVNET",
        "slug": "devnet",
        "description": "This is the environment for network development"
    },
    "vlan": null,
    "status": {
        "value": "active",
        "label": "Active"
    },
    "role": null,
    "is_pool": false,
    "mark_utilized": false,
    "description": "",
    "comments": "",
    "tags": [
        {
            "id": 2,
            "url": "https://192.168.1.82:9443/api/extras/tags/2/",
            "display_url": "https://192.168.1.82:9443/extras/tags/2/",
            "display": "AZR",
            "name": "AZR",
            "slug": "azr",
            "color": "ffe4e1"
        },
        {
            "id": 13,
            "url": "https://192.168.1.82:9443/api/extras/tags/13/",
            "display_url": "https://192.168.1.82:9443/extras/tags/13/",
            "display": "DEVNET",
            "name": "DEVNET",
            "slug": "devnet",
            "color": "ff5722"
        },
        {
            "id": 12,
            "url": "https://192.168.1.82:9443/api/extras/tags/12/",
            "display_url": "https://192.168.1.82:9443/extras/tags/12/",
            "display": "PUBLIC",
            "name": "PUBLIC",
            "slug": "public",
            "color": "607d8b"
        }
    ],
    "custom_fields": {},
    "created": "2025-02-12T17:07:02.075949Z",
    "last_updated": "2025-02-12T17:07:02.075956Z",
    "children": 0,
    "_depth": 0
},
{
    "id": 1199,
    "url": "https://192.168.1.82:9443/api/ipam/prefixes/1199/",
    "display_url": "https://192.168.1.82:9443/ipam/prefixes/1199/",
    "display": "10.128.2.0/24",
    "family": {
        "value": 4,
        "label": "IPv4"
    },
    "prefix": "10.128.2.0/24",
    "vrf": {
        "id": 6,
        "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/",
        "display": "devnet-infra_v3.3",
        "name": "devnet-infra_v3.3",
        "rd": null,
        "description": ""
    },
    "scope_type": null,
    "scope_id": null,
    "scope": null,
    "tenant": {
        "id": 2,
        "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/",
        "display": "DEVNET",
        "name": "DEVNET",
        "slug": "devnet",
        "description": "This is the environment for network development"
    },
    "vlan": null,
    "status": {
        "value": "active",
        "label": "Active"
    },
    "role": null,
    "is_pool": false,
    "mark_utilized": false,
    "description": "",
    "comments": "",
    "tags": [
        {
            "id": 13,
            "url": "https://192.168.1.82:9443/api/extras/tags/13/",
            "display_url": "https://192.168.1.82:9443/extras/tags/13/",
            "display": "DEVNET",
            "name": "DEVNET",
            "slug": "devnet",
            "color": "ff5722"
        },
        {
            "id": 1,
            "url": "https://192.168.1.82:9443/api/extras/tags/1/",
            "display_url": "https://192.168.1.82:9443/extras/tags/1/",
            "display": "GCP",
            "name": "GCP",
            "slug": "gcp",
            "color": "ffe4e1"
        },
        {
            "id": 12,
            "url": "https://192.168.1.82:9443/api/extras/tags/12/",
            "display_url": "https://192.168.1.82:9443/extras/tags/12/",
            "display": "PUBLIC",
            "name": "PUBLIC",
            "slug": "public",
            "color": "607d8b"
        }
    ],
    "custom_fields": {},
    "created": "2025-02-12T17:07:02.101193Z",
    "last_updated": "2025-02-12T17:15:53.791048Z",
    "children": 0,
    "_depth": 1
}
Originally created by @rybakovanton-metta on GitHub (Feb 13, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.2.3 ### Python Version 3.10 ### Steps to Reproduce I creating prefixes via terraform ``` variable "networks" { type = list(object({ cloud = string prefix = string labels = list(string) status = optional(string) })) } resource "netbox_prefix" "tens" { prefix = "10.0.0.0/8" status = "container" tenant_id = var.tenant_id vrf_id = var.vrf_id tags = [upper(var.environment)] } resource "netbox_prefix" "network" { for_each = { for k, v in var.networks : k => v } prefix = each.value.prefix status = each.value.status != null ? each.value.status : "active" tenant_id = var.tenant_id vrf_id = var.vrf_id tags = each.value.cloud == null ? concat([upper(var.environment)], each.value.labels) : concat([upper(each.value.cloud), upper(var.environment)], each.value.labels) } ``` <details> <summary>config inside</summary> ``` "networks": [ { "prefix": "10.128.0.0/10", "labels": [ "INFRA" ], "status": "container" }, { "cloud":"aws", "prefix": "10.128.0.0/24", "labels": [ "PUBLIC" ] }, { "cloud":"azr", "prefix": "10.128.1.0/24", "labels": [ "PUBLIC" ] }, { "cloud":"gcp", "prefix": "10.128.2.0/24", "labels": [ "PUBLIC" ] } ] ``` </details> ### Expected Behavior Prefixes created Container 10/8 have depth = 0 Container 10.128.0.0/10 have depth = 1 Prefixes (10.128.0.0/24, 10.128.1.0/24, 10.128.2.0/24) have the same depth = 2 Children count have a corresponding value. ### Observed Behavior "random" depth one example <img width="624" alt="Image" src="https://github.com/user-attachments/assets/227c1a8a-ad75-4a1e-bec3-9729b05de540" /> another one <img width="614" alt="Image" src="https://github.com/user-attachments/assets/39c31303-9eb0-45c8-ad98-126dd51b6d57" /> <details> <summary>as you can see below, same thing in output fro rest request (_depth attribute)</summary> ``` { "id": 1196, "url": "https://192.168.1.82:9443/api/ipam/prefixes/1196/", "display_url": "https://192.168.1.82:9443/ipam/prefixes/1196/", "display": "10.0.0.0/8", "family": { "value": 4, "label": "IPv4" }, "prefix": "10.0.0.0/8", "vrf": { "id": 6, "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/", "display": "devnet-infra_v3.3", "name": "devnet-infra_v3.3", "rd": null, "description": "" }, "scope_type": null, "scope_id": null, "scope": null, "tenant": { "id": 2, "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "description": "This is the environment for network development" }, "vlan": null, "status": { "value": "container", "label": "Container" }, "role": null, "is_pool": false, "mark_utilized": false, "description": "", "comments": "", "tags": [ { "id": 13, "url": "https://192.168.1.82:9443/api/extras/tags/13/", "display_url": "https://192.168.1.82:9443/extras/tags/13/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "color": "ff5722" } ], "custom_fields": {}, "created": "2025-02-12T17:07:02.035430Z", "last_updated": "2025-02-12T17:07:02.035438Z", "children": 4, "_depth": 0 }, { "id": 1198, "url": "https://192.168.1.82:9443/api/ipam/prefixes/1198/", "display_url": "https://192.168.1.82:9443/ipam/prefixes/1198/", "display": "10.128.0.0/10", "family": { "value": 4, "label": "IPv4" }, "prefix": "10.128.0.0/10", "vrf": { "id": 6, "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/", "display": "devnet-infra_v3.3", "name": "devnet-infra_v3.3", "rd": null, "description": "" }, "scope_type": null, "scope_id": null, "scope": null, "tenant": { "id": 2, "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "description": "This is the environment for network development" }, "vlan": null, "status": { "value": "container", "label": "Container" }, "role": null, "is_pool": false, "mark_utilized": false, "description": "", "comments": "", "tags": [ { "id": 13, "url": "https://192.168.1.82:9443/api/extras/tags/13/", "display_url": "https://192.168.1.82:9443/extras/tags/13/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "color": "ff5722" } ], "custom_fields": {}, "created": "2025-02-12T17:07:02.078119Z", "last_updated": "2025-02-12T17:07:02.078126Z", "children": 3, "_depth": 0 }, { "id": 1204, "url": "https://192.168.1.82:9443/api/ipam/prefixes/1204/", "display_url": "https://192.168.1.82:9443/ipam/prefixes/1204/", "display": "10.128.0.0/24", "family": { "value": 4, "label": "IPv4" }, "prefix": "10.128.0.0/24", "vrf": { "id": 6, "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/", "display": "devnet-infra_v3.3", "name": "devnet-infra_v3.3", "rd": null, "description": "" }, "scope_type": null, "scope_id": null, "scope": null, "tenant": { "id": 2, "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "description": "This is the environment for network development" }, "vlan": null, "status": { "value": "active", "label": "Active" }, "role": null, "is_pool": false, "mark_utilized": false, "description": "", "comments": "", "tags": [ { "id": 3, "url": "https://192.168.1.82:9443/api/extras/tags/3/", "display_url": "https://192.168.1.82:9443/extras/tags/3/", "display": "AWS", "name": "AWS", "slug": "aws", "color": "ffe4e1" }, { "id": 13, "url": "https://192.168.1.82:9443/api/extras/tags/13/", "display_url": "https://192.168.1.82:9443/extras/tags/13/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "color": "ff5722" }, { "id": 12, "url": "https://192.168.1.82:9443/api/extras/tags/12/", "display_url": "https://192.168.1.82:9443/extras/tags/12/", "display": "PUBLIC", "name": "PUBLIC", "slug": "public", "color": "607d8b" } ], "custom_fields": {}, "created": "2025-02-12T17:34:26.645054Z", "last_updated": "2025-02-12T17:34:26.645059Z", "children": 0, "_depth": 2 }, { "id": 1197, "url": "https://192.168.1.82:9443/api/ipam/prefixes/1197/", "display_url": "https://192.168.1.82:9443/ipam/prefixes/1197/", "display": "10.128.1.0/24", "family": { "value": 4, "label": "IPv4" }, "prefix": "10.128.1.0/24", "vrf": { "id": 6, "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/", "display": "devnet-infra_v3.3", "name": "devnet-infra_v3.3", "rd": null, "description": "" }, "scope_type": null, "scope_id": null, "scope": null, "tenant": { "id": 2, "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "description": "This is the environment for network development" }, "vlan": null, "status": { "value": "active", "label": "Active" }, "role": null, "is_pool": false, "mark_utilized": false, "description": "", "comments": "", "tags": [ { "id": 2, "url": "https://192.168.1.82:9443/api/extras/tags/2/", "display_url": "https://192.168.1.82:9443/extras/tags/2/", "display": "AZR", "name": "AZR", "slug": "azr", "color": "ffe4e1" }, { "id": 13, "url": "https://192.168.1.82:9443/api/extras/tags/13/", "display_url": "https://192.168.1.82:9443/extras/tags/13/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "color": "ff5722" }, { "id": 12, "url": "https://192.168.1.82:9443/api/extras/tags/12/", "display_url": "https://192.168.1.82:9443/extras/tags/12/", "display": "PUBLIC", "name": "PUBLIC", "slug": "public", "color": "607d8b" } ], "custom_fields": {}, "created": "2025-02-12T17:07:02.075949Z", "last_updated": "2025-02-12T17:07:02.075956Z", "children": 0, "_depth": 0 }, { "id": 1199, "url": "https://192.168.1.82:9443/api/ipam/prefixes/1199/", "display_url": "https://192.168.1.82:9443/ipam/prefixes/1199/", "display": "10.128.2.0/24", "family": { "value": 4, "label": "IPv4" }, "prefix": "10.128.2.0/24", "vrf": { "id": 6, "url": "https://192.168.1.82:9443/api/ipam/vrfs/6/", "display": "devnet-infra_v3.3", "name": "devnet-infra_v3.3", "rd": null, "description": "" }, "scope_type": null, "scope_id": null, "scope": null, "tenant": { "id": 2, "url": "https://192.168.1.82:9443/api/tenancy/tenants/2/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "description": "This is the environment for network development" }, "vlan": null, "status": { "value": "active", "label": "Active" }, "role": null, "is_pool": false, "mark_utilized": false, "description": "", "comments": "", "tags": [ { "id": 13, "url": "https://192.168.1.82:9443/api/extras/tags/13/", "display_url": "https://192.168.1.82:9443/extras/tags/13/", "display": "DEVNET", "name": "DEVNET", "slug": "devnet", "color": "ff5722" }, { "id": 1, "url": "https://192.168.1.82:9443/api/extras/tags/1/", "display_url": "https://192.168.1.82:9443/extras/tags/1/", "display": "GCP", "name": "GCP", "slug": "gcp", "color": "ffe4e1" }, { "id": 12, "url": "https://192.168.1.82:9443/api/extras/tags/12/", "display_url": "https://192.168.1.82:9443/extras/tags/12/", "display": "PUBLIC", "name": "PUBLIC", "slug": "public", "color": "607d8b" } ], "custom_fields": {}, "created": "2025-02-12T17:07:02.101193Z", "last_updated": "2025-02-12T17:15:53.791048Z", "children": 0, "_depth": 1 } ``` </details>
adam added the type: bugpending closurestatus: revisions needed labels 2025-12-29 21:35:45 +01:00
adam closed this issue 2025-12-29 21:35:45 +01:00
Author
Owner

@arthanson commented on GitHub (Feb 13, 2025):

@rybakovanton-metta Can you please add some repro steps for manual creation, rather then terraform?

@arthanson commented on GitHub (Feb 13, 2025): @rybakovanton-metta Can you please add some repro steps for manual creation, rather then terraform?
Author
Owner

@github-actions[bot] commented on GitHub (Feb 21, 2025):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Feb 21, 2025): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@github-actions[bot] commented on GitHub (Mar 1, 2025):

This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.

@github-actions[bot] commented on GitHub (Mar 1, 2025): This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10768