-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathapplyresourcechange.go
67 lines (47 loc) · 2.03 KB
/
applyresourcechange.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
package fromproto5
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
)
// ApplyResourceChangeRequest returns the *fwserver.ApplyResourceChangeRequest
// equivalent of a *tfprotov5.ApplyResourceChangeRequest.
func ApplyResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.ApplyResourceChangeRequest, resourceType provider.ResourceType, resourceSchema *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ApplyResourceChangeRequest, diag.Diagnostics) {
if proto5 == nil {
return nil, nil
}
var diags diag.Diagnostics
// Panic prevention here to simplify the calling implementations.
// This should not happen, but just in case.
if resourceSchema == nil {
diags.AddError(
"Missing Resource Schema",
"An unexpected error was encountered when handling the request. "+
"This is always an issue in terraform-plugin-framework used to implement the provider and should be reported to the provider developers.\n\n"+
"Please report this to the provider developer:\n\n"+
"Missing schema.",
)
return nil, diags
}
fw := &fwserver.ApplyResourceChangeRequest{
PlannedPrivate: proto5.PlannedPrivate,
ResourceSchema: *resourceSchema,
ResourceType: resourceType,
}
config, configDiags := Config(ctx, proto5.Config, resourceSchema)
diags.Append(configDiags...)
fw.Config = config
plannedState, plannedStateDiags := Plan(ctx, proto5.PlannedState, resourceSchema)
diags.Append(plannedStateDiags...)
fw.PlannedState = plannedState
priorState, priorStateDiags := State(ctx, proto5.PriorState, resourceSchema)
diags.Append(priorStateDiags...)
fw.PriorState = priorState
providerMeta, providerMetaDiags := ProviderMeta(ctx, proto5.ProviderMeta, providerMetaSchema)
diags.Append(providerMetaDiags...)
fw.ProviderMeta = providerMeta
return fw, diags
}