Name for devices is now optional
This commit is contained in:
parent
797fe93a9a
commit
3a970ac852
3 changed files with 27 additions and 7 deletions
|
|
@ -42,7 +42,7 @@ type Site struct {
|
||||||
type Device struct {
|
type Device struct {
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
SiteID string `json:"site_id"`
|
SiteID string `json:"site_id"`
|
||||||
Name string `json:"name"`
|
Name *string `json:"name,omitempty"`
|
||||||
IPAddress string `json:"ip_address"`
|
IPAddress string `json:"ip_address"`
|
||||||
Description *string `json:"description,omitempty"`
|
Description *string `json:"description,omitempty"`
|
||||||
MonitoringEnabled *bool `json:"monitoring_enabled,omitempty"`
|
MonitoringEnabled *bool `json:"monitoring_enabled,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,9 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"name": schema.StringAttribute{
|
"name": schema.StringAttribute{
|
||||||
Description: "The name of the device.",
|
Description: "The name of the device. If not provided, will be auto-discovered.",
|
||||||
Required: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
},
|
},
|
||||||
"ip_address": schema.StringAttribute{
|
"ip_address": schema.StringAttribute{
|
||||||
Description: "The IP address of the device.",
|
Description: "The IP address of the device.",
|
||||||
|
|
@ -138,10 +139,14 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest,
|
||||||
|
|
||||||
device := Device{
|
device := Device{
|
||||||
SiteID: data.SiteID.ValueString(),
|
SiteID: data.SiteID.ValueString(),
|
||||||
Name: data.Name.ValueString(),
|
|
||||||
IPAddress: data.IPAddress.ValueString(),
|
IPAddress: data.IPAddress.ValueString(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !data.Name.IsNull() {
|
||||||
|
name := data.Name.ValueString()
|
||||||
|
device.Name = &name
|
||||||
|
}
|
||||||
|
|
||||||
if !data.Description.IsNull() {
|
if !data.Description.IsNull() {
|
||||||
desc := data.Description.ValueString()
|
desc := data.Description.ValueString()
|
||||||
device.Description = &desc
|
device.Description = &desc
|
||||||
|
|
@ -176,6 +181,10 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest,
|
||||||
data.ID = types.StringValue(created.ID)
|
data.ID = types.StringValue(created.ID)
|
||||||
data.InsertedAt = types.StringValue(created.InsertedAt)
|
data.InsertedAt = types.StringValue(created.InsertedAt)
|
||||||
|
|
||||||
|
if created.Name != nil {
|
||||||
|
data.Name = types.StringValue(*created.Name)
|
||||||
|
}
|
||||||
|
|
||||||
if created.MonitoringEnabled != nil {
|
if created.MonitoringEnabled != nil {
|
||||||
data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled)
|
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.SiteID = types.StringValue(device.SiteID)
|
||||||
data.Name = types.StringValue(device.Name)
|
|
||||||
data.IPAddress = types.StringValue(device.IPAddress)
|
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)
|
data.InsertedAt = types.StringValue(device.InsertedAt)
|
||||||
|
|
||||||
if device.Description != nil {
|
if device.Description != nil {
|
||||||
|
|
@ -240,10 +254,14 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest,
|
||||||
|
|
||||||
device := Device{
|
device := Device{
|
||||||
SiteID: data.SiteID.ValueString(),
|
SiteID: data.SiteID.ValueString(),
|
||||||
Name: data.Name.ValueString(),
|
|
||||||
IPAddress: data.IPAddress.ValueString(),
|
IPAddress: data.IPAddress.ValueString(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !data.Name.IsNull() {
|
||||||
|
name := data.Name.ValueString()
|
||||||
|
device.Name = &name
|
||||||
|
}
|
||||||
|
|
||||||
if !data.Description.IsNull() {
|
if !data.Description.IsNull() {
|
||||||
desc := data.Description.ValueString()
|
desc := data.Description.ValueString()
|
||||||
device.Description = &desc
|
device.Description = &desc
|
||||||
|
|
@ -275,9 +293,11 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Name = types.StringValue(updated.Name)
|
|
||||||
data.IPAddress = types.StringValue(updated.IPAddress)
|
data.IPAddress = types.StringValue(updated.IPAddress)
|
||||||
|
|
||||||
|
if updated.Name != nil {
|
||||||
|
data.Name = types.StringValue(*updated.Name)
|
||||||
|
}
|
||||||
if updated.Description != nil {
|
if updated.Description != nil {
|
||||||
data.Description = types.StringValue(*updated.Description)
|
data.Description = types.StringValue(*updated.Description)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Reference in a new issue