From 4d6aefa74d73fe286bc327a9927c7e0e4eb79811 Mon Sep 17 00:00:00 2001 From: Thibault Bustarret Date: Wed, 12 Jun 2024 17:29:40 +0200 Subject: [PATCH] fix: avoid override of device's values on primary ip creation and update --- netbox/resource_netbox_device_primary_ip.go | 40 ++------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/netbox/resource_netbox_device_primary_ip.go b/netbox/resource_netbox_device_primary_ip.go index a66f9895..5f2ebb14 100644 --- a/netbox/resource_netbox_device_primary_ip.go +++ b/netbox/resource_netbox_device_primary_ip.go @@ -101,6 +101,7 @@ func resourceNetboxDevicePrimaryIPUpdate(d *schema.ResourceData, m interface{}) // then update the FULL device with ALL tracked attributes data := models.WritableDeviceWithConfigContext{} + data.Name = device.Name data.Tags = device.Tags // the netbox API sends the URL property as part of NestedTag, but it does not accept the URL property when we send it back @@ -111,25 +112,14 @@ func resourceNetboxDevicePrimaryIPUpdate(d *schema.ResourceData, m interface{}) tag.Display = "" } - data.Comments = device.Comments - data.Serial = device.Serial - if device.DeviceType != nil { data.DeviceType = &device.DeviceType.ID } - if device.Cluster != nil { - data.Cluster = &device.Cluster.ID - } - if device.Site != nil { data.Site = &device.Site.ID } - if device.Location != nil { - data.Location = &device.Location.ID - } - if device.Role != nil { data.Role = &device.Role.ID } @@ -142,30 +132,6 @@ func resourceNetboxDevicePrimaryIPUpdate(d *schema.ResourceData, m interface{}) data.PrimaryIp6 = &device.PrimaryIp6.ID } - if device.Platform != nil { - data.Platform = &device.Platform.ID - } - - if device.Tenant != nil { - data.Tenant = &device.Tenant.ID - } - - if device.Status != nil { - data.Status = *device.Status.Value - } - - if device.Rack != nil { - data.Rack = &device.Rack.ID - } - - if device.Face != nil { - data.Face = *device.Face.Value - } - - if device.Position != nil { - data.Position = device.Position - } - // unset primary ip address if -1 is passed as id if IPAddressID == -1 { if IPAddressVersion == 4 { @@ -181,9 +147,9 @@ func resourceNetboxDevicePrimaryIPUpdate(d *schema.ResourceData, m interface{}) } } - updateParams := dcim.NewDcimDevicesUpdateParams().WithID(deviceID).WithData(&data) + updateParams := dcim.NewDcimDevicesPartialUpdateParams().WithID(deviceID).WithData(&data) - _, err = api.Dcim.DcimDevicesUpdate(updateParams, nil) + _, err = api.Dcim.DcimDevicesPartialUpdate(updateParams, nil) if err != nil { return err }