Skip to content

Commit 0b1f804

Browse files
author
Paddy Carver
committed
Upgrade gRPC and protobuf versions.
We're now generating our tfplugin5 package using libprotoc v3.13.0, protoc-gen-go v1.25.0, and protoc-gen-go-grpc v1.0. This required updating all our protocol conversions to use pointers instead of concrete values to make Go vet happy, as most request types in the generated tfplugin5 package now had sync.Mutexes in them, and go vet complained about us copying the sync.Mutex.
1 parent 70e3716 commit 0b1f804

23 files changed

+4733
-3098
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/vmihailenco/msgpack v4.0.4+incompatible
1010
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
1111
google.golang.org/appengine v1.6.5 // indirect
12-
google.golang.org/grpc v1.31.0
12+
google.golang.org/grpc v1.32.0
13+
google.golang.org/protobuf v1.23.0
1314
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
1415
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi
9898
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
9999
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
100100
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
101-
google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI=
102-
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
101+
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
102+
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
103103
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
104104
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
105105
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

tfprotov5/internal/fromproto/attribute_path.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99

1010
var ErrUnknownAttributePathStepType = errors.New("unknown type of AttributePath_Step")
1111

12-
func AttributePath(in tfplugin5.AttributePath) (tfprotov5.AttributePath, error) {
12+
func AttributePath(in *tfplugin5.AttributePath) (*tfprotov5.AttributePath, error) {
1313
steps, err := AttributePathSteps(in.Steps)
1414
if err != nil {
15-
return tfprotov5.AttributePath{}, err
15+
return nil, err
1616
}
17-
return tfprotov5.AttributePath{
17+
return &tfprotov5.AttributePath{
1818
Steps: steps,
1919
}, nil
2020
}
@@ -26,16 +26,16 @@ func AttributePaths(in []*tfplugin5.AttributePath) ([]*tfprotov5.AttributePath,
2626
resp = append(resp, nil)
2727
continue
2828
}
29-
attr, err := AttributePath(*a)
29+
attr, err := AttributePath(a)
3030
if err != nil {
3131
return resp, err
3232
}
33-
resp = append(resp, &attr)
33+
resp = append(resp, attr)
3434
}
3535
return resp, nil
3636
}
3737

38-
func AttributePathStep(step tfplugin5.AttributePath_Step) (tfprotov5.AttributePathStep, error) {
38+
func AttributePathStep(step *tfplugin5.AttributePath_Step) (tfprotov5.AttributePathStep, error) {
3939
selector := step.GetSelector()
4040
if v, ok := selector.(*tfplugin5.AttributePath_Step_AttributeName); ok {
4141
return tfprotov5.AttributeName(v.AttributeName), nil
@@ -55,7 +55,7 @@ func AttributePathSteps(in []*tfplugin5.AttributePath_Step) ([]tfprotov5.Attribu
5555
if step == nil {
5656
continue
5757
}
58-
s, err := AttributePathStep(*step)
58+
s, err := AttributePathStep(step)
5959
if err != nil {
6060
return resp, err
6161
}

tfprotov5/internal/fromproto/data_source.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,49 @@ import (
55
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
66
)
77

8-
func ValidateDataSourceConfigRequest(in tfplugin5.ValidateDataSourceConfig_Request) (tfprotov5.ValidateDataSourceConfigRequest, error) {
9-
resp := tfprotov5.ValidateDataSourceConfigRequest{
8+
func ValidateDataSourceConfigRequest(in *tfplugin5.ValidateDataSourceConfig_Request) (*tfprotov5.ValidateDataSourceConfigRequest, error) {
9+
resp := &tfprotov5.ValidateDataSourceConfigRequest{
1010
TypeName: in.TypeName,
1111
}
1212
if in.Config != nil {
13-
config := DynamicValue(*in.Config)
14-
resp.Config = &config
13+
resp.Config = DynamicValue(in.Config)
1514
}
1615
return resp, nil
1716
}
1817

19-
func ValidateDataSourceConfigResponse(in tfplugin5.ValidateDataSourceConfig_Response) (tfprotov5.ValidateDataSourceConfigResponse, error) {
20-
var resp tfprotov5.ValidateDataSourceConfigResponse
18+
func ValidateDataSourceConfigResponse(in *tfplugin5.ValidateDataSourceConfig_Response) (*tfprotov5.ValidateDataSourceConfigResponse, error) {
2119
diags, err := Diagnostics(in.Diagnostics)
2220
if err != nil {
23-
return tfprotov5.ValidateDataSourceConfigResponse{}, err
21+
return nil, err
2422
}
25-
resp.Diagnostics = diags
26-
return resp, nil
23+
return &tfprotov5.ValidateDataSourceConfigResponse{
24+
Diagnostics: diags,
25+
}, nil
2726
}
2827

29-
func ReadDataSourceRequest(in tfplugin5.ReadDataSource_Request) (tfprotov5.ReadDataSourceRequest, error) {
30-
resp := tfprotov5.ReadDataSourceRequest{
28+
func ReadDataSourceRequest(in *tfplugin5.ReadDataSource_Request) (*tfprotov5.ReadDataSourceRequest, error) {
29+
resp := &tfprotov5.ReadDataSourceRequest{
3130
TypeName: in.TypeName,
3231
}
3332
if in.Config != nil {
34-
config := DynamicValue(*in.Config)
35-
resp.Config = &config
33+
resp.Config = DynamicValue(in.Config)
3634
}
3735
if in.ProviderMeta != nil {
38-
meta := DynamicValue(*in.ProviderMeta)
39-
resp.ProviderMeta = &meta
36+
resp.ProviderMeta = DynamicValue(in.ProviderMeta)
4037
}
4138
return resp, nil
4239
}
4340

44-
func ReadDataSourceResponse(in tfplugin5.ReadDataSource_Response) (tfprotov5.ReadDataSourceResponse, error) {
45-
var resp tfprotov5.ReadDataSourceResponse
41+
func ReadDataSourceResponse(in *tfplugin5.ReadDataSource_Response) (*tfprotov5.ReadDataSourceResponse, error) {
4642
diags, err := Diagnostics(in.Diagnostics)
4743
if err != nil {
48-
return resp, err
44+
return nil, err
45+
}
46+
resp := &tfprotov5.ReadDataSourceResponse{
47+
Diagnostics: diags,
4948
}
50-
resp.Diagnostics = diags
5149
if in.State != nil {
52-
state := DynamicValue(*in.State)
53-
resp.State = &state
50+
resp.State = DynamicValue(in.State)
5451
}
5552
return resp, nil
5653
}

tfprotov5/internal/fromproto/diagnostic.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import (
55
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
66
)
77

8-
func Diagnostic(in tfplugin5.Diagnostic) (tfprotov5.Diagnostic, error) {
9-
diag := tfprotov5.Diagnostic{
8+
func Diagnostic(in *tfplugin5.Diagnostic) (*tfprotov5.Diagnostic, error) {
9+
diag := &tfprotov5.Diagnostic{
1010
Severity: DiagnosticSeverity(in.Severity),
1111
Summary: in.Summary,
1212
Detail: in.Detail,
1313
}
1414
if in.Attribute != nil {
15-
attr, err := AttributePath(*in.Attribute)
15+
attr, err := AttributePath(in.Attribute)
1616
if err != nil {
1717
return diag, err
1818
}
19-
diag.Attribute = &attr
19+
diag.Attribute = attr
2020
}
2121
return diag, nil
2222
}
@@ -32,11 +32,11 @@ func Diagnostics(in []*tfplugin5.Diagnostic) ([]*tfprotov5.Diagnostic, error) {
3232
diagnostics = append(diagnostics, nil)
3333
continue
3434
}
35-
d, err := Diagnostic(*diag)
35+
d, err := Diagnostic(diag)
3636
if err != nil {
3737
return diagnostics, err
3838
}
39-
diagnostics = append(diagnostics, &d)
39+
diagnostics = append(diagnostics, d)
4040
}
4141
return diagnostics, nil
4242
}
Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,109 @@
11
package fromproto
22

33
import (
4-
"fmt"
5-
64
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
75
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
86
)
97

10-
func GetProviderSchemaRequest(in tfplugin5.GetProviderSchema_Request) (tfprotov5.GetProviderSchemaRequest, error) {
11-
return tfprotov5.GetProviderSchemaRequest{}, nil
8+
func GetProviderSchemaRequest(in *tfplugin5.GetProviderSchema_Request) (*tfprotov5.GetProviderSchemaRequest, error) {
9+
return &tfprotov5.GetProviderSchemaRequest{}, nil
1210
}
1311

14-
func GetProviderSchemaResponse(in tfplugin5.GetProviderSchema_Response) (tfprotov5.GetProviderSchemaResponse, error) {
12+
func GetProviderSchemaResponse(in *tfplugin5.GetProviderSchema_Response) (*tfprotov5.GetProviderSchemaResponse, error) {
1513
var resp tfprotov5.GetProviderSchemaResponse
1614
if in.Provider != nil {
17-
schema, err := Schema(*in.Provider)
15+
schema, err := Schema(in.Provider)
1816
if err != nil {
19-
return resp, err
17+
return &resp, err
2018
}
21-
resp.Provider = &schema
19+
resp.Provider = schema
2220
}
2321
if in.ProviderMeta != nil {
24-
schema, err := Schema(*in.ProviderMeta)
22+
schema, err := Schema(in.ProviderMeta)
2523
if err != nil {
26-
return resp, err
24+
return &resp, err
2725
}
28-
resp.ProviderMeta = &schema
26+
resp.ProviderMeta = schema
2927
}
3028
resp.ResourceSchemas = make(map[string]*tfprotov5.Schema, len(in.ResourceSchemas))
3129
for k, v := range in.ResourceSchemas {
3230
if v == nil {
3331
resp.ResourceSchemas[k] = nil
3432
continue
3533
}
36-
schema, err := Schema(*v)
34+
schema, err := Schema(v)
3735
if err != nil {
38-
return resp, err
36+
return &resp, err
3937
}
40-
resp.ResourceSchemas[k] = &schema
38+
resp.ResourceSchemas[k] = schema
4139
}
4240
resp.DataSourceSchemas = make(map[string]*tfprotov5.Schema, len(in.DataSourceSchemas))
4341
for k, v := range in.DataSourceSchemas {
4442
if v == nil {
4543
resp.DataSourceSchemas[k] = nil
4644
continue
4745
}
48-
schema, err := Schema(*v)
46+
schema, err := Schema(v)
4947
if err != nil {
50-
return resp, err
48+
return &resp, err
5149
}
52-
resp.DataSourceSchemas[k] = &schema
50+
resp.DataSourceSchemas[k] = schema
5351
}
5452
diags, err := Diagnostics(in.Diagnostics)
5553
if err != nil {
56-
return resp, err
54+
return &resp, err
5755
}
5856
resp.Diagnostics = diags
59-
return resp, nil
57+
return &resp, nil
6058
}
6159

62-
func PrepareProviderConfigRequest(in tfplugin5.PrepareProviderConfig_Request) (tfprotov5.PrepareProviderConfigRequest, error) {
60+
func PrepareProviderConfigRequest(in *tfplugin5.PrepareProviderConfig_Request) (*tfprotov5.PrepareProviderConfigRequest, error) {
6361
var resp tfprotov5.PrepareProviderConfigRequest
6462
if in.Config != nil {
65-
config := DynamicValue(*in.Config)
66-
resp.Config = &config
63+
resp.Config = DynamicValue(in.Config)
6764
}
68-
return resp, nil
65+
return &resp, nil
6966
}
7067

71-
func PrepareProviderConfigResponse(in tfplugin5.PrepareProviderConfig_Response) (tfprotov5.PrepareProviderConfigResponse, error) {
68+
func PrepareProviderConfigResponse(in *tfplugin5.PrepareProviderConfig_Response) (*tfprotov5.PrepareProviderConfigResponse, error) {
7269
var resp tfprotov5.PrepareProviderConfigResponse
7370
diags, err := Diagnostics(in.Diagnostics)
7471
if err != nil {
75-
return resp, err
72+
return nil, err
7673
}
7774
resp.Diagnostics = diags
7875
if in.PreparedConfig != nil {
79-
config := DynamicValue(*in.PreparedConfig)
80-
if err != nil {
81-
return resp, fmt.Errorf("Error converting config: %w", err)
82-
}
83-
resp.PreparedConfig = &config
76+
resp.PreparedConfig = DynamicValue(in.PreparedConfig)
8477
}
85-
return resp, nil
78+
return &resp, nil
8679
}
8780

88-
func ConfigureProviderRequest(in tfplugin5.Configure_Request) (tfprotov5.ConfigureProviderRequest, error) {
89-
resp := tfprotov5.ConfigureProviderRequest{
81+
func ConfigureProviderRequest(in *tfplugin5.Configure_Request) (*tfprotov5.ConfigureProviderRequest, error) {
82+
resp := &tfprotov5.ConfigureProviderRequest{
9083
TerraformVersion: in.TerraformVersion,
9184
}
9285
if in.Config != nil {
93-
config := DynamicValue(*in.Config)
94-
resp.Config = &config
86+
resp.Config = DynamicValue(in.Config)
9587
}
9688
return resp, nil
9789
}
9890

99-
func ConfigureProviderResponse(in tfplugin5.Configure_Response) (tfprotov5.ConfigureProviderResponse, error) {
100-
var resp tfprotov5.ConfigureProviderResponse
91+
func ConfigureProviderResponse(in *tfplugin5.Configure_Response) (*tfprotov5.ConfigureProviderResponse, error) {
10192
diags, err := Diagnostics(in.Diagnostics)
10293
if err != nil {
103-
return resp, err
94+
return nil, err
10495
}
105-
resp.Diagnostics = diags
106-
return resp, nil
96+
return &tfprotov5.ConfigureProviderResponse{
97+
Diagnostics: diags,
98+
}, nil
10799
}
108100

109-
func StopProviderRequest(in tfplugin5.Stop_Request) (tfprotov5.StopProviderRequest, error) {
110-
return tfprotov5.StopProviderRequest{}, nil
101+
func StopProviderRequest(in *tfplugin5.Stop_Request) (*tfprotov5.StopProviderRequest, error) {
102+
return &tfprotov5.StopProviderRequest{}, nil
111103
}
112104

113-
func StopProviderResponse(in tfplugin5.Stop_Response) (tfprotov5.StopProviderResponse, error) {
114-
return tfprotov5.StopProviderResponse{
105+
func StopProviderResponse(in *tfplugin5.Stop_Response) (*tfprotov5.StopProviderResponse, error) {
106+
return &tfprotov5.StopProviderResponse{
115107
Error: in.Error,
116108
}, nil
117109
}

0 commit comments

Comments
 (0)