/
provider.go
125 lines (114 loc) · 3.69 KB
/
provider.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package toproto
import (
"fmt"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
)
func GetProviderSchema_Request(in *tfprotov5.GetProviderSchemaRequest) (*tfplugin5.GetProviderSchema_Request, error) {
return &tfplugin5.GetProviderSchema_Request{}, nil
}
func GetProviderSchema_Response(in *tfprotov5.GetProviderSchemaResponse) (*tfplugin5.GetProviderSchema_Response, error) {
if in == nil {
return nil, nil
}
resp := tfplugin5.GetProviderSchema_Response{
ServerCapabilities: GetProviderSchema_ServerCapabilities(in.ServerCapabilities),
}
if in.Provider != nil {
schema, err := Schema(in.Provider)
if err != nil {
return &resp, fmt.Errorf("error marshaling provider schema: %w", err)
}
resp.Provider = schema
}
if in.ProviderMeta != nil {
schema, err := Schema(in.ProviderMeta)
if err != nil {
return &resp, fmt.Errorf("error marshaling provider_meta schema: %w", err)
}
resp.ProviderMeta = schema
}
resp.ResourceSchemas = make(map[string]*tfplugin5.Schema, len(in.ResourceSchemas))
for k, v := range in.ResourceSchemas {
if v == nil {
resp.ResourceSchemas[k] = nil
continue
}
schema, err := Schema(v)
if err != nil {
return &resp, fmt.Errorf("error marshaling resource schema for %q: %w", k, err)
}
resp.ResourceSchemas[k] = schema
}
resp.DataSourceSchemas = make(map[string]*tfplugin5.Schema, len(in.DataSourceSchemas))
for k, v := range in.DataSourceSchemas {
if v == nil {
resp.DataSourceSchemas[k] = nil
continue
}
schema, err := Schema(v)
if err != nil {
return &resp, fmt.Errorf("error marshaling data source schema for %q: %w", k, err)
}
resp.DataSourceSchemas[k] = schema
}
diags, err := Diagnostics(in.Diagnostics)
if err != nil {
return &resp, err
}
resp.Diagnostics = diags
return &resp, nil
}
func PrepareProviderConfig_Request(in *tfprotov5.PrepareProviderConfigRequest) (*tfplugin5.PrepareProviderConfig_Request, error) {
resp := &tfplugin5.PrepareProviderConfig_Request{}
if in.Config != nil {
resp.Config = DynamicValue(in.Config)
}
return resp, nil
}
func PrepareProviderConfig_Response(in *tfprotov5.PrepareProviderConfigResponse) (*tfplugin5.PrepareProviderConfig_Response, error) {
diags, err := Diagnostics(in.Diagnostics)
if err != nil {
return nil, err
}
resp := &tfplugin5.PrepareProviderConfig_Response{
Diagnostics: diags,
}
if in.PreparedConfig != nil {
resp.PreparedConfig = DynamicValue(in.PreparedConfig)
}
return resp, nil
}
func Configure_Request(in *tfprotov5.ConfigureProviderRequest) (*tfplugin5.Configure_Request, error) {
resp := &tfplugin5.Configure_Request{
TerraformVersion: in.TerraformVersion,
}
if in.Config != nil {
resp.Config = DynamicValue(in.Config)
}
return resp, nil
}
func Configure_Response(in *tfprotov5.ConfigureProviderResponse) (*tfplugin5.Configure_Response, error) {
diags, err := Diagnostics(in.Diagnostics)
if err != nil {
return nil, err
}
return &tfplugin5.Configure_Response{
Diagnostics: diags,
}, nil
}
func Stop_Request(in *tfprotov5.StopProviderRequest) (*tfplugin5.Stop_Request, error) {
return &tfplugin5.Stop_Request{}, nil
}
func Stop_Response(in *tfprotov5.StopProviderResponse) (*tfplugin5.Stop_Response, error) {
return &tfplugin5.Stop_Response{
Error: in.Error,
}, nil
}
// we have to say this next thing to get golint to stop yelling at us about the
// underscores in the function names. We want the function names to match
// actually-generated code, so it feels like fair play. It's just a shame we
// lose golint for the entire file.
//
// This file is not actually generated. You can edit it. Ignore this next line.
// Code generated by hand ignore this next bit DO NOT EDIT.