Skip to content

Commit 87c3bcf

Browse files
committed
further clean up
1 parent 709841f commit 87c3bcf

File tree

7 files changed

+12
-28
lines changed

7 files changed

+12
-28
lines changed

internal/fwschemadata/data_set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package fwschemadata
66
import (
77
"context"
88
"fmt"
9-
"github.com/hashicorp/terraform-plugin-go/tftypes"
109

1110
"github.com/hashicorp/terraform-plugin-framework/diag"
1211
"github.com/hashicorp/terraform-plugin-framework/internal/reflect"
1312
"github.com/hashicorp/terraform-plugin-framework/path"
13+
"github.com/hashicorp/terraform-plugin-go/tftypes"
1414
)
1515

1616
// Set replaces the entire value. The value can be a tftypes.Value or a struct whose fields

internal/fwserver/server_getmetadata_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ func TestServerGetMetadata(t *testing.T) {
839839
diag.NewErrorDiagnostic(
840840
"ListResource Type Defined without a Matching Managed Resource Type",
841841
"The test_resource_1 ListResource type name was returned, but no matching managed Resource type was defined. "+
842+
"If the matching managed Resource type is a legacy resource, ProtoV5Schema and ProtoV5IdentitySchema must be specified in the Metadata method. "+
842843
"This is always an issue with the provider and should be reported to the provider developers.",
843844
),
844845
},

internal/fwserver/server_listresource.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/hashicorp/terraform-plugin-framework/list"
1414
"github.com/hashicorp/terraform-plugin-framework/resource"
1515
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
16-
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
1716
"github.com/hashicorp/terraform-plugin-go/tftypes"
1817
)
1918

@@ -50,8 +49,6 @@ type ListResultsStream struct {
5049
// Results is a function that emits [ListResult] values via its push
5150
// function argument.
5251
Results iter.Seq[ListResult]
53-
54-
ResultsProtoV5 iter.Seq[tfprotov5.ListResourceResult]
5552
}
5653

5754
func ListResultError(summary string, detail string) ListResult {
@@ -62,18 +59,6 @@ func ListResultError(summary string, detail string) ListResult {
6259
}
6360
}
6461

65-
func ListResultErrorProto5(summary string, detail string) tfprotov5.ListResourceResult {
66-
return tfprotov5.ListResourceResult{
67-
Diagnostics: []*tfprotov5.Diagnostic{
68-
{
69-
Severity: 1,
70-
Summary: summary,
71-
Detail: detail,
72-
},
73-
},
74-
}
75-
}
76-
7762
// ListResult represents a listed managed resource instance.
7863
type ListResult struct {
7964
// Identity is the identity of the managed resource instance. A nil value
@@ -121,8 +106,6 @@ func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream
121106
if listResourceWithConfigure, ok := listResource.(list.ListResourceWithConfigure); ok {
122107
logging.FrameworkTrace(ctx, "ListResource implements ListResourceWithConfigure")
123108

124-
// ListResourceConfigureData isn't populated in the ConfigureProvider RPC
125-
// We can use ResourceConfigureData here for now or populate ListResourceConfigureData
126109
configureReq := resource.ConfigureRequest{
127110
ProviderData: s.ListResourceConfigureData,
128111
}

internal/fwserver/server_listresources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ func (s *Server) ListResourceFuncs(ctx context.Context) (map[string]func() list.
8787

8888
resourceFuncs, _ := s.ResourceFuncs(ctx)
8989
if _, ok := resourceFuncs[typeName]; !ok {
90-
// TODO update error message
9190
if metadataResp.ProtoV5Schema == nil || metadataResp.ProtoV5IdentitySchema == nil {
9291
s.listResourceFuncsDiags.AddError(
9392
"ListResource Type Defined without a Matching Managed Resource Type",
9493
fmt.Sprintf("The %s ListResource type name was returned, but no matching managed Resource type was defined. ", typeName)+
94+
"If the matching managed Resource type is a legacy resource, ProtoV5Schema and ProtoV5IdentitySchema must be specified in the Metadata method. "+
9595
"This is always an issue with the provider and should be reported to the provider developers.",
9696
)
9797
continue

internal/proto5server/server_listresource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s *Server) ListResource(ctx context.Context, protoReq *tfprotov5.ListResou
5858
Limit: protoReq.Limit,
5959
}
6060

61-
// There's validation in xxx that ensures both are set if either is provided so perhaps it's sufficient to only nil check Identity
61+
// There's validation in ListResources that ensures both are set if either is provided so it should be sufficient to only nil check Identity
6262
if metadataResp.ProtoV5IdentitySchema != nil {
6363
req.ResourceSchema, _ = fromproto5.ResourceSchema(ctx, metadataResp.ProtoV5Schema())
6464
req.ResourceIdentitySchema, _ = fromproto5.IdentitySchema(ctx, metadataResp.ProtoV5IdentitySchema())

list/metadata.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
package list
55

6-
import "github.com/hashicorp/terraform-plugin-go/tfprotov5"
7-
86
// MetadataRequest represents a request for the ListResource to return metadata,
97
// such as its type name. An instance of this request struct is supplied as
108
// an argument to the ListResource type Metadata method.
@@ -23,9 +21,4 @@ type MetadataResponse struct {
2321
// TypeName should be the full list resource type, including the provider
2422
// type prefix and an underscore. For example, examplecloud_thing.
2523
TypeName string
26-
27-
// Could this also live in the Schema instead? Should it?
28-
// If it's here we can do validation
29-
ProtoV5Schema func() *tfprotov5.Schema
30-
ProtoV5IdentitySchema func() *tfprotov5.ResourceIdentitySchema
3124
}

resource/metadata.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ type MetadataResponse struct {
2828
// interacting with this resource.
2929
ResourceBehavior ResourceBehavior
3030

31-
ProtoV5Schema func() *tfprotov5.Schema
31+
// ProtoV5IdentitySchema is the ProtoV5 representation of the resource identity
32+
// schema. This should only be supplied if framework functionality is being used
33+
// with a legacy resource. Currently, this only applies to list.
3234
ProtoV5IdentitySchema func() *tfprotov5.ResourceIdentitySchema
35+
36+
// ProtoV5Schema is the ProtoV5 representation of the resource schema
37+
// This should only be supplied if framework functionality is being used
38+
// with a legacy resource. Currently, this only applies to list.
39+
ProtoV5Schema func() *tfprotov5.Schema
3340
}
3441

3542
// ResourceBehavior controls framework-specific logic when interacting

0 commit comments

Comments
 (0)