/
readresource.go
47 lines (31 loc) · 1.37 KB
/
readresource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package fromproto5
import (
"context"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/provider"
)
// ReadResourceRequest returns the *fwserver.ReadResourceRequest
// equivalent of a *tfprotov5.ReadResourceRequest.
func ReadResourceRequest(ctx context.Context, proto5 *tfprotov5.ReadResourceRequest, resourceType provider.ResourceType, resourceSchema fwschema.Schema, providerMetaSchema fwschema.Schema) (*fwserver.ReadResourceRequest, diag.Diagnostics) {
if proto5 == nil {
return nil, nil
}
var diags diag.Diagnostics
fw := &fwserver.ReadResourceRequest{
ResourceType: resourceType,
}
currentState, currentStateDiags := State(ctx, proto5.CurrentState, resourceSchema)
diags.Append(currentStateDiags...)
fw.CurrentState = currentState
providerMeta, providerMetaDiags := ProviderMeta(ctx, proto5.ProviderMeta, providerMetaSchema)
diags.Append(providerMetaDiags...)
fw.ProviderMeta = providerMeta
privateData, privateDataDiags := privatestate.NewData(ctx, proto5.Private)
diags.Append(privateDataDiags...)
fw.Private = privateData
return fw, diags
}