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

Add serial number to system datasource #63

Merged
merged 1 commit into from
Nov 27, 2024
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
34 changes: 34 additions & 0 deletions internal/datasources/system/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/client"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/constants"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/systems/privatecloudbusiness"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
Expand Down Expand Up @@ -156,8 +157,41 @@ func (s *DataSource) Read(
return
}

// TODO: Switch to GetStorageSerial() when FF-31483 is fixed
serial := system.GetStorageSystem().GetAdditionalData()["serialNumber"]
if serial == nil {
resp.Diagnostics.AddError(
"error reading system",
"storage serial number is nil",
)

return
}
serialNumber, ok := serial.(*string)
if !ok {
resp.Diagnostics.AddError(
"error reading system",
"storage serial number cannot be cast to *string",
)

return
}

data.Name = types.StringValue(*name)
data.Id = types.StringValue(*id)

value := map[string]attr.Value{
"storage_serial": types.StringValue(*serialNumber),
}
storageSystem, diags := NewStorageSystemValue(
data.StorageSystem.AttributeTypes(ctx), value,
)

resp.Diagnostics.Append((diags)...)
if resp.Diagnostics.HasError() {
return
}
data.StorageSystem = storageSystem

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
9 changes: 9 additions & 0 deletions test/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func TestAccSystemDataSource(t *testing.T) {
"array-5305-grp",
),
checkUUIDAttr("data.hpegl_pc_system.test", "id"),
resource.TestCheckResourceAttrSet(
"data.hpegl_pc_system.test",
"storage_system.storage_serial",
),
}

if simulation {
Expand All @@ -86,6 +90,11 @@ func TestAccSystemDataSource(t *testing.T) {
"id",
"126fd201-9e6e-5e31-9ffb-a766265b1fd3",
),
resource.TestCheckResourceAttr(
"data.hpegl_pc_system.test",
"storage_system.storage_serial",
"AF-836032",
),
)
}

Expand Down