Name for devices is now optional

This commit is contained in:
Graham McIntire 2026-01-26 13:36:06 -06:00
parent 797fe93a9a
commit 3a970ac852
No known key found for this signature in database
3 changed files with 27 additions and 7 deletions

View file

@ -42,7 +42,7 @@ type Site struct {
type Device struct {
ID string `json:"id,omitempty"`
SiteID string `json:"site_id"`
Name string `json:"name"`
Name *string `json:"name,omitempty"`
IPAddress string `json:"ip_address"`
Description *string `json:"description,omitempty"`
MonitoringEnabled *bool `json:"monitoring_enabled,omitempty"`

View file

@ -65,8 +65,9 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest,
},
},
"name": schema.StringAttribute{
Description: "The name of the device.",
Required: true,
Description: "The name of the device. If not provided, will be auto-discovered.",
Optional: true,
Computed: true,
},
"ip_address": schema.StringAttribute{
Description: "The IP address of the device.",
@ -138,10 +139,14 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest,
device := Device{
SiteID: data.SiteID.ValueString(),
Name: data.Name.ValueString(),
IPAddress: data.IPAddress.ValueString(),
}
if !data.Name.IsNull() {
name := data.Name.ValueString()
device.Name = &name
}
if !data.Description.IsNull() {
desc := data.Description.ValueString()
device.Description = &desc
@ -176,6 +181,10 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest,
data.ID = types.StringValue(created.ID)
data.InsertedAt = types.StringValue(created.InsertedAt)
if created.Name != nil {
data.Name = types.StringValue(*created.Name)
}
if created.MonitoringEnabled != nil {
data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled)
}
@ -201,8 +210,13 @@ func (r *DeviceResource) Read(ctx context.Context, req resource.ReadRequest, res
}
data.SiteID = types.StringValue(device.SiteID)
data.Name = types.StringValue(device.Name)
data.IPAddress = types.StringValue(device.IPAddress)
if device.Name != nil {
data.Name = types.StringValue(*device.Name)
} else {
data.Name = types.StringNull()
}
data.InsertedAt = types.StringValue(device.InsertedAt)
if device.Description != nil {
@ -240,10 +254,14 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest,
device := Device{
SiteID: data.SiteID.ValueString(),
Name: data.Name.ValueString(),
IPAddress: data.IPAddress.ValueString(),
}
if !data.Name.IsNull() {
name := data.Name.ValueString()
device.Name = &name
}
if !data.Description.IsNull() {
desc := data.Description.ValueString()
device.Description = &desc
@ -275,9 +293,11 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest,
return
}
data.Name = types.StringValue(updated.Name)
data.IPAddress = types.StringValue(updated.IPAddress)
if updated.Name != nil {
data.Name = types.StringValue(*updated.Name)
}
if updated.Description != nil {
data.Description = types.StringValue(*updated.Description)
}

Binary file not shown.