Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid override of device's values on primary ip creation and update #610

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions netbox/resource_netbox_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,6 @@ func resourceNetboxDeviceUpdate(ctx context.Context, d *schema.ResourceData, m i
data.ConfigTemplate = &configTemplateID
}

primaryIP4Value, ok := d.GetOk("primary_ipv4")
if ok {
primaryIP4 := int64(primaryIP4Value.(int))
data.PrimaryIp4 = &primaryIP4
}

primaryIP6Value, ok := d.GetOk("primary_ipv6")
if ok {
primaryIP6 := int64(primaryIP6Value.(int))
data.PrimaryIp6 = &primaryIP6
}

data.Rack = getOptionalInt(d, "rack_id")
data.Face = getOptionalStr(d, "rack_face", false)
data.Position = getOptionalFloat(d, "rack_position")
Expand Down
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
Loading
Loading