smutel / terraform-provider-netbox

Terraform provider for Netbox
ISC License
58 stars 19 forks source link

Custom fields default values not null #180

Closed sloweclair closed 1 year ago

sloweclair commented 1 year ago

Summary

In Netbox 3.4.5 (Not supported yet by this provider) the default values for custom fields are empty strings and not null.

Version

Netbox version

028f7ce1ac02 (v3.4.5)

Terraform version

1.3.9

Provider version

6.1.0

Issue details

Affected Data(s) / Resource(s)

Terraform Configuration Files


resource "netbox_extras_custom_field" "cf_object" {
  name = "cf_object"
  label = "CF object"
  type = "object"
  content_types = [
    "dcim.site",
  ]
  object_type = "dcim.platform"
  description = "Test object field"
}

resource "netbox_extras_custom_field" "cf_json" {
  name = "cf_json"
  label = "CF Json"
  type = "json"
  content_types = [
    "dcim.site",
  ]
  description = "Test multiobject field"
  default = jsonencode({
      bool = false
      number = 1.5
      dict = {
          text = "Some text"
      }
  })
}

Terraform Output

No error

Behaviors

Actual Behavior

The unset default values are empty strings for all the types, including integer, date, json, etc. For the json type it encodes the JSON and netbox doesn't know how to handle it.

Expected Behavior

The default values should be represented as JSON values. In the database the column type is jsonb.

Running the following command on custom fields made by terraform vs manually shows the difference in the default values. The query I use is

select "type", "default" from extras_customfield

Manual

image

Terraform

image

Steps to Reproduce

  1. terraform apply