Skip to content

Commit 8603aea

Browse files
committed
fixup! Implement ListResource RPC in proto6server
1 parent ff407da commit 8603aea

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

internal/toproto6/list_resource_result.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package toproto6
33
import (
44
"context"
55

6-
"github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata"
76
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
87
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
98
)
@@ -37,11 +36,7 @@ func ListResourceResultWithResource(ctx context.Context, result *fwserver.ListRe
3736
resourceIdentity, d := ResourceIdentity(ctx, result.Identity)
3837
diags.Append(d...)
3938

40-
resource, d := DynamicValue(ctx, &fwschemadata.Data{
41-
Description: fwschemadata.DataDescriptionResource,
42-
Schema: result.Resource.Schema,
43-
TerraformValue: result.Resource.Raw,
44-
})
39+
resource, d := Resource(ctx, result.Resource)
4540
diags.Append(d...)
4641

4742
return tfprotov6.ListResourceResult{

internal/toproto6/resource.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package toproto6
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/diag"
10+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata"
11+
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
12+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
13+
)
14+
15+
// Resource returns the *tfprotov6.DynamicValue for a *tfsdk.Resource.
16+
func Resource(ctx context.Context, fw *tfsdk.Resource) (*tfprotov6.DynamicValue, diag.Diagnostics) {
17+
if fw == nil {
18+
return nil, nil
19+
}
20+
21+
data := &fwschemadata.Data{
22+
Description: fwschemadata.DataDescriptionResource,
23+
Schema: fw.Schema,
24+
TerraformValue: fw.Raw,
25+
}
26+
27+
return DynamicValue(ctx, data)
28+
}

0 commit comments

Comments
 (0)