@@ -12,11 +12,13 @@ import (
1212 "github.com/hashicorp/terraform-plugin-go/tftypes"
1313
1414 "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/datasource"
15+ "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/list"
1516 "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/provider"
1617 "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource"
1718)
1819
1920var _ tfprotov6.ProviderServer = ProviderServer {}
21+ var _ tfprotov6.ProviderServerWithListResource = ProviderServer {}
2022
2123// NewProviderServer returns a lightweight protocol version 6 provider server
2224// for consumption with ProtoV6ProviderFactories.
@@ -86,6 +88,12 @@ func (s ProviderServer) GetMetadata(ctx context.Context, request *tfprotov6.GetM
8688 })
8789 }
8890
91+ for typeName := range s .Provider .ListResourcesMap () {
92+ resp .ListResources = append (resp .ListResources , tfprotov6.ListResourceMetadata {
93+ TypeName : typeName ,
94+ })
95+ }
96+
8997 for typeName := range s .Provider .ResourcesMap () {
9098 resp .Resources = append (resp .Resources , tfprotov6.ResourceMetadata {
9199 TypeName : typeName ,
@@ -304,10 +312,11 @@ func (s ProviderServer) GetProviderSchema(ctx context.Context, req *tfprotov6.Ge
304312 Functions : map [string ]* tfprotov6.Function {},
305313 EphemeralResourceSchemas : map [string ]* tfprotov6.Schema {},
306314
307- DataSourceSchemas : map [string ]* tfprotov6.Schema {},
308- Diagnostics : providerResp .Diagnostics ,
309- Provider : providerResp .Schema ,
310- ResourceSchemas : map [string ]* tfprotov6.Schema {},
315+ DataSourceSchemas : map [string ]* tfprotov6.Schema {},
316+ Diagnostics : providerResp .Diagnostics ,
317+ ListResourceSchemas : map [string ]* tfprotov6.Schema {},
318+ Provider : providerResp .Schema ,
319+ ResourceSchemas : map [string ]* tfprotov6.Schema {},
311320 ServerCapabilities : & tfprotov6.ServerCapabilities {
312321 PlanDestroy : true ,
313322 },
@@ -324,6 +333,17 @@ func (s ProviderServer) GetProviderSchema(ctx context.Context, req *tfprotov6.Ge
324333 resp .DataSourceSchemas [typeName ] = schemaResp .Schema
325334 }
326335
336+ for typeName , l := range s .Provider .ListResourcesMap () {
337+ schemaReq := list.SchemaRequest {}
338+ schemaResp := & list.SchemaResponse {}
339+
340+ l .Schema (ctx , schemaReq , schemaResp )
341+
342+ resp .Diagnostics = append (resp .Diagnostics , schemaResp .Diagnostics ... )
343+
344+ resp .ListResourceSchemas [typeName ] = schemaResp .Schema
345+ }
346+
327347 for typeName , r := range s .Provider .ResourcesMap () {
328348 schemaReq := resource.SchemaRequest {}
329349 schemaResp := & resource.SchemaResponse {}
@@ -1017,3 +1037,47 @@ func (s ProviderServer) CloseEphemeralResource(ctx context.Context, req *tfproto
10171037func (s ProviderServer ) ValidateEphemeralResourceConfig (ctx context.Context , req * tfprotov6.ValidateEphemeralResourceConfigRequest ) (* tfprotov6.ValidateEphemeralResourceConfigResponse , error ) {
10181038 return & tfprotov6.ValidateEphemeralResourceConfigResponse {}, nil
10191039}
1040+
1041+ func (s ProviderServer ) ListResource (ctx context.Context , req * tfprotov6.ListResourceRequest ) (* tfprotov6.ListResourceServerStream , error ) {
1042+ resp := & tfprotov6.ListResourceServerStream {}
1043+
1044+ // Copy over identity if it's supported
1045+ identitySchemaReq := resource.IdentitySchemaRequest {}
1046+ identitySchemaResp := & resource.IdentitySchemaResponse {}
1047+
1048+ r , _ := ProviderResource (s .Provider , req .TypeName )
1049+ // TODO: diag
1050+ r .IdentitySchema (ctx , identitySchemaReq , identitySchemaResp )
1051+
1052+ results := func (push func (tfprotov6.ListResourceResult ) bool ) {
1053+ _ , diag := ProviderListResource (s .Provider , req .TypeName )
1054+ if diag != nil {
1055+ push (tfprotov6.ListResourceResult {Diagnostics : []* tfprotov6.Diagnostic {diag }})
1056+ return
1057+ }
1058+
1059+ identityData := tftypes .NewValue (
1060+ tftypes.Object {
1061+ AttributeTypes : map [string ]tftypes.Type {
1062+ "id" : tftypes .String ,
1063+ },
1064+ },
1065+ map [string ]tftypes.Value {
1066+ "id" : tftypes .NewValue (tftypes .String , "westeurope/somevalue" ),
1067+ },
1068+ )
1069+ identity , _ := IdentityValuetoDynamicValue (identitySchemaResp .Schema , identityData ) // TODO: diag
1070+ push (tfprotov6.ListResourceResult {
1071+ Identity : & tfprotov6.ResourceIdentityData {
1072+ IdentityData : identity ,
1073+ },
1074+ })
1075+ }
1076+
1077+ resp .Results = results
1078+ return resp , nil
1079+ }
1080+
1081+ func (s ProviderServer ) ValidateListResourceConfig (ctx context.Context , req * tfprotov6.ValidateListResourceConfigRequest ) (* tfprotov6.ValidateListResourceConfigResponse , error ) {
1082+ return & tfprotov6.ValidateListResourceConfigResponse {}, nil
1083+ }
0 commit comments