smutel / terraform-provider-netbox

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

fix: Prevent panic if vcpus is null #147

Closed amhn closed 1 year ago

amhn commented 1 year ago

Fixes: #82

Creating a VM without vcpus did not work because the addition of ".00" prevented the latter check for "" from working. This resulted in sending "vpus": 0 which is not allowed in netbox.

Additionally a read of a VM without vcpus failed with a panic because netbox sends null as value for vcpus.

Setting vcpus back to null does not work because of limitations in go-swagger or the json library in go. See the primary_ip issue. This is currently silently ignored in the Update.

smutel commented 1 year ago

I did some tests and I have a strange behavior. I am using the file examples/main.tf.

Terraform will perform the following actions:

netbox_ipam_ip_addresses.ip_test must be replaced

-/+ resource "netbox_ipam_ip_addresses" "ip_test" { ~ content_type = "ipam.ipaddresse" -> (known after apply) ~ id = "49" -> (known after apply)

amhn commented 1 year ago

Yes. This is triggered by https://github.com/smutel/go-netbox/commit/c6308a5357f811ccd0c64aa492d59bb63c4f274e

Any change of the virtual machine sets the primary_ip4 back to null. I noticed this but did not have time to report this yet.

This is unrelated to my changes. A change in the description would trigger the same replacement.

smutel commented 1 year ago

OK, il will try to fix that in my PR for IPv6.