Open brunoofe-te opened 1 year ago
@fbreckle I think this is an issue with the definition of custom_fields
and its custom_schema
. I don't think it needs a custom definition of a type here, I think it should be a TypeMap
, as TypeMap
is a Golang map[string]interface
which would be exactly what is expected. I should be able to hand a set of keys and whatever values to the custom fields. The fact values are forced to be strings means that values other than strings, which is possible with custom_fields
, won't be available to the end user. Defining custom_fields
as a TypeMap
shouldn't be excessively difficult to do.
Edit: I went digging, and the data source is set as a TypeMap already, so why is the resource a custom value? Testing with the API on v3.5.0 (sorry, I upgraded already), the following appears to be true:
Boolean
, a boolean value must be suppliedInteger
, an integer value must be suppliedDecimal
, a float value will be inferred from a string, as JSON does not allow random .
characters in fields that aren't quoted stringsJSON
, a JSON object is expected. If you pass it a string, the JSON object becomes just a string. This is probably not expected.Mutliple Object
or Multiple Selection
, a set of strings must be suppliedDate
, Date&Time
, and URL
.There is a tiny issue with the NetBox API, in that it will allow you to specify a URL that is non-functional (URLs require http://
or https://
to be valid if you edit from the WebUI, but the api just does it)
While it won't be possible to restrict the values that people include in the custom_fields
and it won't be something users can be assisted with (in completions, etc), that's really their problem. If they create a custom_field
it should be up to them to get the type of value correct.
I'm unsure if we should expect NetBox to infer value based on a string->type
conversion, and therefore register this as an issue with the NetBox API, or whether we should take it upon this project to redo all the custom_fields
definitions to schema.TypeMap
and risk breaking people's previous implementations (though, it shouldn't I believe).
i've also encountered this and it looks like the terraform-plugin-sdk
used in this provider does not allow managing attributes with a map that has mixed types. this means terraform will always coalesce the values in the map to strings.
One could consider different ways to approach this:
Hi,
When I try to create or update a netbox_virtual_machine with an Integer type custom field, I get this error:
Error: [POST /virtualization/virtual-machines/][400] virtualization_virtual-machines_create default map[__all__:[Invalid value for custom field 'max_num_agents': Value must be an integer.]]
Terraform Version
Affected Resource(s)
At least:
Terraform Configuration Files
Relevant part
Debug Output
https://gist.github.com/brunoofe-te/849b7084499fdd7cc88af19514eb1745
Panic Output
N/A
Expected Behavior
The Virtualization > virtual machine object should be created in NetBox with the Integer type custom field correctly set.
Actual Behavior
Error: [POST /virtualization/virtual-machines/][400] virtualization_virtual-machines_create default map[all:[Invalid value for custom field 'max_num_agents': Value must be an integer.]]
Steps to Reproduce
terraform apply
Important Factoids
N/A