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
173 stars 117 forks source link

increase slug size for all objects #573

Closed jpengenheiro closed 3 months ago

jpengenheiro commented 4 months ago

Hi,

The slug field can be increased to 100 chars, and currently for version 3.5.5 of this provider the limit is hardcoded to 30.

I ran the following command in my netbox install to search for the limit of the slug field across all objects that have it:

$ find . -type d -name models -execdir sh -c 'cd models; find . -type f -name "*.py" | while read file; do cat -n $file | perl -lane "print if /slug =
 models\.SlugField\(/ .. /\s*\)/"; done' \;
    94      slug = models.SlugField(
    95          max_length=100
    96      )
   136      slug = models.SlugField(
   137          max_length=100,
   138          unique=True
   139      )
    21      slug = models.SlugField(
    22          max_length=100,
    23          unique=True
    24      )
    42      slug = models.SlugField(
    43          max_length=100,
    44          unique=True
    45      )
    82      slug = models.SlugField(
    83          max_length=100
    84      )
   149      slug = models.SlugField(
   150          max_length=100,
   151          unique=True
   152      )
   383      slug = models.SlugField(
   384          max_length=100,
   385          unique=True
   386      )
    23      slug = models.SlugField(
    24          max_length=100,
    25          unique=True
    26      )
    29      slug = models.SlugField(
    30          max_length=100
    31      )
    22      slug = models.SlugField(
    23          max_length=100,
    24          unique=True
    25      )

Affected Resource(s)

I tested on:

but there seem to be others that have the same limitation

Terraform Configuration Files

resource "netbox_tenant" "tenant-something" {
  slug = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  name = "some name"
}

Expected Behavior

the plugin should accept the slugs

Actual Behavior

terraform validate throws an error:

Error: expected length of slug to be in the range (0 - 30), got xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

  with netbox_tenant.tenant-something,
  on tenants-from-snow.tf line 38, in resource "netbox_tenant" "tenant-something":
  38:   slug = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Important Factoids

I run netbox version 3.4.4, all slugs are valid UUIDs and netbox accepts them

References

this seems to already have been mentioned for sites:

fbreckle commented 4 months ago

True.

Since you seem to be using perl, took a pity on you and fixed it straight away in #574.

:D

jpengenheiro commented 4 months ago

@fbreckle thanks!

perl is useful for a few things...

will this be available in any 3.5.* version?

fbreckle commented 4 months ago

No, I do not have the capacity to maintain multiple release branches in parallel, so I just fix stuff going forward.

However, depending on what resources you use, you can usually just try using a newer provider version. Webhooks, ASNs and custom field choice sets are the resources breaking between 3.5 and 3.8.

If you really need it, I could release a 3.5. version. Although, IMO, you should just update your netbox. ;)

jpengenheiro commented 4 months ago

I'll try using 3.8.5 once it reaches the terraform registry, a netbox update won't happen for a while

fbreckle commented 4 months ago

Yeah, we currently have some issues with the github webhook that publishes to the registry. I'm on it.

jpengenheiro commented 4 months ago

no hurry,

thanks for all the help