Skip to content

Commit

Permalink
fix: avoid override of device's values on primary ip creation and update
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultbustarret-ovhcloud committed Jun 12, 2024
1 parent c377748 commit 4d6aefa
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions netbox/resource_netbox_device_primary_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 4d6aefa

Please sign in to comment.