From 588762b6446d9e689d438348fe56a7cbf75ad323 Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 20 Aug 2025 11:27:12 +0200 Subject: [PATCH] set empty objects in NewListResult --- internal/proto5server/server_listresource_test.go | 2 +- internal/proto6server/server_listresource_test.go | 4 ++-- list/list_resource.go | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/proto5server/server_listresource_test.go b/internal/proto5server/server_listresource_test.go index 1b68ec8c3..b9aeb5a99 100644 --- a/internal/proto5server/server_listresource_test.go +++ b/internal/proto5server/server_listresource_test.go @@ -105,7 +105,7 @@ func TestServerListResource(t *testing.T) { continue } - result := req.NewListResult() + result := req.NewListResult(ctx) result.DisplayName = name diags = result.Identity.Set(ctx, resources[name].ThingResourceIdentity) diff --git a/internal/proto6server/server_listresource_test.go b/internal/proto6server/server_listresource_test.go index 831f6e4a6..0811f5a57 100644 --- a/internal/proto6server/server_listresource_test.go +++ b/internal/proto6server/server_listresource_test.go @@ -105,7 +105,7 @@ func TestServerListResource(t *testing.T) { continue } - result := req.NewListResult() + result := req.NewListResult(ctx) result.DisplayName = name diags = result.Identity.Set(ctx, resources[name].ThingResourceIdentity) @@ -131,7 +131,7 @@ func TestServerListResource(t *testing.T) { } r.ListMethod = func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { - result := req.NewListResult() + result := req.NewListResult(ctx) result.DisplayName = "plateau" diags := result.Identity.Set(ctx, resources["plateau"].ThingResourceIdentity) diff --git a/list/list_resource.go b/list/list_resource.go index 09f46ce8d..3dbdbee17 100644 --- a/list/list_resource.go +++ b/list/list_resource.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-go/tftypes" ) // ListResource represents an implementation of listing instances of a managed resource @@ -109,9 +110,15 @@ type ListRequest struct { // NewListResult creates a new [ListResult] with convenient defaults // for each field. -func (r ListRequest) NewListResult() ListResult { - identity := &tfsdk.ResourceIdentity{Schema: r.ResourceIdentitySchema} - resource := &tfsdk.Resource{Schema: r.ResourceSchema} +func (r ListRequest) NewListResult(ctx context.Context) ListResult { + identity := &tfsdk.ResourceIdentity{ + Raw: tftypes.NewValue(r.ResourceIdentitySchema.Type().TerraformType(ctx), nil), + Schema: r.ResourceIdentitySchema, + } + resource := &tfsdk.Resource{ + Raw: tftypes.NewValue(r.ResourceSchema.Type().TerraformType(ctx), nil), + Schema: r.ResourceSchema, + } return ListResult{ DisplayName: "",