-
Notifications
You must be signed in to change notification settings - Fork 94
/
server_planresourcechange.go
67 lines (44 loc) · 2.02 KB
/
server_planresourcechange.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package proto6server
import (
"context"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto6"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/logging"
"github.com/hashicorp/terraform-plugin-framework/internal/toproto6"
)
// PlanResourceChange satisfies the tfprotov6.ProviderServer interface.
func (s *Server) PlanResourceChange(ctx context.Context, proto6Req *tfprotov6.PlanResourceChangeRequest) (*tfprotov6.PlanResourceChangeResponse, error) {
ctx = s.registerContext(ctx)
ctx = logging.InitContext(ctx)
fwResp := &fwserver.PlanResourceChangeResponse{}
resource, diags := s.FrameworkServer.Resource(ctx, proto6Req.TypeName)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto6.PlanResourceChangeResponse(ctx, fwResp), nil
}
resourceSchema, diags := s.FrameworkServer.ResourceSchema(ctx, proto6Req.TypeName)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto6.PlanResourceChangeResponse(ctx, fwResp), nil
}
providerMetaSchema, diags := s.FrameworkServer.ProviderMetaSchema(ctx)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto6.PlanResourceChangeResponse(ctx, fwResp), nil
}
resourceBehavior, diags := s.FrameworkServer.ResourceBehavior(ctx, proto6Req.TypeName)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto6.PlanResourceChangeResponse(ctx, fwResp), nil
}
fwReq, diags := fromproto6.PlanResourceChangeRequest(ctx, proto6Req, resource, resourceSchema, providerMetaSchema, resourceBehavior)
fwResp.Diagnostics.Append(diags...)
if fwResp.Diagnostics.HasError() {
return toproto6.PlanResourceChangeResponse(ctx, fwResp), nil
}
s.FrameworkServer.PlanResourceChange(ctx, fwReq, fwResp)
return toproto6.PlanResourceChangeResponse(ctx, fwResp), nil
}