-
Notifications
You must be signed in to change notification settings - Fork 91
/
server_upgraderesourcestate.go
51 lines (35 loc) · 1.59 KB
/
server_upgraderesourcestate.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
48
49
50
51
package proto5server
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/logging"
"github.com/hashicorp/terraform-plugin-framework/internal/toproto5"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
)
// UpgradeResourceState satisfies the tfprotov5.ProviderServer interface.
func (s *Server) UpgradeResourceState(ctx context.Context, proto5Req *tfprotov5.UpgradeResourceStateRequest) (*tfprotov5.UpgradeResourceStateResponse, error) {
ctx = s.registerContext(ctx)
ctx = logging.InitContext(ctx)
fwResp := &fwserver.UpgradeResourceStateResponse{}
if proto5Req == nil {
return toproto5.UpgradeResourceStateResponse(ctx, fwResp), nil
}
resource, diags := s.FrameworkServer.Resource(ctx, proto5Req.TypeName)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto5.UpgradeResourceStateResponse(ctx, fwResp), nil
}
resourceSchema, diags := s.FrameworkServer.ResourceSchema(ctx, proto5Req.TypeName)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto5.UpgradeResourceStateResponse(ctx, fwResp), nil
}
fwReq, diags := fromproto5.UpgradeResourceStateRequest(ctx, proto5Req, resource, resourceSchema)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto5.UpgradeResourceStateResponse(ctx, fwResp), nil
}
s.FrameworkServer.UpgradeResourceState(ctx, fwReq, fwResp)
return toproto5.UpgradeResourceStateResponse(ctx, fwResp), nil
}