Skip to content

Commit 23e467a

Browse files
authored
all: Remove type assertions for Function and MoveResourceState RPC implementations (#238)
* all: Remove FunctionServer type assertions * all: Remove ResourceServerWithMoveResourceState type assertions
1 parent 7469931 commit 23e467a

20 files changed

+40
-477
lines changed

tf5muxserver/mux_server.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ import (
1515

1616
var _ tfprotov5.ProviderServer = &muxServer{}
1717

18-
// Temporarily verify that v5tov6Server implements new RPCs correctly.
19-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
20-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
21-
var (
22-
_ tfprotov5.FunctionServer = &muxServer{}
23-
//nolint:staticcheck // Intentional verification of interface implementation.
24-
_ tfprotov5.ResourceServerWithMoveResourceState = &muxServer{}
25-
)
26-
2718
// muxServer is a gRPC server implementation that stands in front of other
2819
// gRPC servers, routing requests to them as if they were a single server. It
2920
// should always be instantiated by calling NewMuxServer().

tf5muxserver/mux_server_CallFunction.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,7 @@ func (s *muxServer) CallFunction(ctx context.Context, req *tfprotov5.CallFunctio
4646
}
4747

4848
ctx = logging.Tfprotov5ProviderServerContext(ctx, server)
49-
50-
// Remove and call server.CallFunction below directly.
51-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
52-
functionServer, ok := server.(tfprotov5.FunctionServer)
53-
54-
if !ok {
55-
resp := &tfprotov5.CallFunctionResponse{
56-
Error: &tfprotov5.FunctionError{
57-
Text: "Provider Functions Not Implemented: A provider-defined function call was received by the provider, however the provider does not implement functions. " +
58-
"Either upgrade the provider to a version that implements provider-defined functions or this is a bug in Terraform that should be reported to the Terraform maintainers.",
59-
},
60-
}
61-
62-
return resp, nil
63-
}
64-
6549
logging.MuxTrace(ctx, "calling downstream server")
6650

67-
// return server.CallFunction(ctx, req)
68-
return functionServer.CallFunction(ctx, req)
51+
return server.CallFunction(ctx, req)
6952
}

tf5muxserver/mux_server_CallFunction_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,7 @@ func TestMuxServerCallFunction(t *testing.T) {
3939
t.Fatalf("unexpected error setting up factory: %s", err)
4040
}
4141

42-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
43-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
44-
45-
if !ok {
46-
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
47-
}
48-
49-
// _, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
50-
_, err = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
42+
_, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
5143
Name: "test_function1",
5244
})
5345

@@ -63,8 +55,7 @@ func TestMuxServerCallFunction(t *testing.T) {
6355
t.Errorf("unexpected test_function1 CallFunction called on server2")
6456
}
6557

66-
// _, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
67-
_, err = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
58+
_, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
6859
Name: "test_function2",
6960
})
7061

tf5muxserver/mux_server_GetFunctions.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,9 @@ func (s *muxServer) GetFunctions(ctx context.Context, req *tfprotov5.GetFunction
3030
for _, server := range s.servers {
3131
ctx := logging.Tfprotov5ProviderServerContext(ctx, server)
3232

33-
// Remove and call server.GetFunctions below directly.
34-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
35-
functionServer, ok := server.(tfprotov5.FunctionServer)
36-
37-
if !ok {
38-
continue
39-
}
40-
4133
logging.MuxTrace(ctx, "calling downstream server")
4234

43-
// serverResp, err := server.GetFunctions(ctx, &tfprotov5.GetFunctionsRequest{})
44-
serverResp, err := functionServer.GetFunctions(ctx, &tfprotov5.GetFunctionsRequest{})
35+
serverResp, err := server.GetFunctions(ctx, &tfprotov5.GetFunctionsRequest{})
4536

4637
if err != nil {
4738
return resp, fmt.Errorf("error calling GetFunctions for %T: %w", server, err)

tf5muxserver/mux_server_GetFunctions_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,7 @@ func TestMuxServerGetFunctions(t *testing.T) {
311311
t.Fatalf("unexpected error: %s", err)
312312
}
313313

314-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
315-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
316-
317-
if !ok {
318-
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
319-
}
320-
321-
// resp, err := muxServer.ProviderServer().GetFunctions(context.Background(), &tfprotov5.GetFunctionsRequest{})
322-
resp, err := functionServer.GetFunctions(context.Background(), &tfprotov5.GetFunctionsRequest{})
314+
resp, err := muxServer.ProviderServer().GetFunctions(context.Background(), &tfprotov5.GetFunctionsRequest{})
323315

324316
if err != nil {
325317
t.Fatalf("unexpected error: %s", err)

tf5muxserver/mux_server_MoveResourceState.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,7 @@ func (s *muxServer) MoveResourceState(ctx context.Context, req *tfprotov5.MoveRe
3030
}
3131

3232
ctx = logging.Tfprotov5ProviderServerContext(ctx, server)
33-
34-
// Remove and call server.MoveResourceState below directly.
35-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
36-
//nolint:staticcheck // Intentionally verifying interface implementation
37-
resourceServer, ok := server.(tfprotov5.ResourceServerWithMoveResourceState)
38-
39-
if !ok {
40-
resp := &tfprotov5.MoveResourceStateResponse{
41-
Diagnostics: []*tfprotov5.Diagnostic{
42-
{
43-
Severity: tfprotov5.DiagnosticSeverityError,
44-
Summary: "MoveResourceState Not Implemented",
45-
Detail: "A MoveResourceState call was received by the provider, however the provider does not implement MoveResourceState. " +
46-
"Either upgrade the provider to a version that implements MoveResourceState or this is a bug in Terraform that should be reported to the Terraform maintainers.",
47-
},
48-
},
49-
}
50-
51-
return resp, nil
52-
}
53-
5433
logging.MuxTrace(ctx, "calling downstream server")
5534

56-
// return server.MoveResourceState(ctx, req)
57-
return resourceServer.MoveResourceState(ctx, req)
35+
return server.MoveResourceState(ctx, req)
5836
}

tf5muxserver/mux_server_MoveResourceState_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,7 @@ func TestMuxServerMoveResourceState(t *testing.T) {
3939
t.Fatalf("unexpected error setting up factory: %s", err)
4040
}
4141

42-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
43-
//nolint:staticcheck // Intentionally verifying interface implementation
44-
resourceServer, ok := muxServer.ProviderServer().(tfprotov5.ResourceServerWithMoveResourceState)
45-
46-
if !ok {
47-
t.Fatal("muxServer should implement tfprotov5.ResourceServerWithMoveResourceState")
48-
}
49-
50-
// _, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
51-
_, err = resourceServer.MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
42+
_, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
5243
TargetTypeName: "test_resource1",
5344
})
5445

@@ -64,8 +55,7 @@ func TestMuxServerMoveResourceState(t *testing.T) {
6455
t.Errorf("unexpected test_resource1 MoveResourceState called on server2")
6556
}
6657

67-
// _, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
68-
_, err = resourceServer.MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
58+
_, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
6959
TargetTypeName: "test_resource2",
7060
})
7161

tf5muxserver/mux_server_test.go

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,7 @@ func TestMuxServerGetFunctionServer_GetProviderSchema(t *testing.T) {
435435
terraformOp := func() {
436436
defer wg.Done()
437437

438-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
439-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
440-
441-
if !ok {
442-
t.Error("muxServer should implement tfprotov5.FunctionServer")
443-
}
444-
445-
// _, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
446-
_, _ = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
438+
_, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
447439
Name: "test_function1",
448440
})
449441
}
@@ -502,15 +494,7 @@ func TestMuxServerGetFunctionServer_GetProviderSchema_Duplicate(t *testing.T) {
502494
terraformOp := func() {
503495
defer wg.Done()
504496

505-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
506-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
507-
508-
if !ok {
509-
t.Error("muxServer should implement tfprotov5.FunctionServer")
510-
}
511-
512-
// resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
513-
resp, _ := functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
497+
resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
514498
Name: "test_function",
515499
})
516500

@@ -574,15 +558,7 @@ func TestMuxServerGetFunctionServer_GetMetadata(t *testing.T) {
574558
terraformOp := func() {
575559
defer wg.Done()
576560

577-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
578-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
579-
580-
if !ok {
581-
t.Error("muxServer should implement tfprotov5.FunctionServer")
582-
}
583-
584-
// _, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
585-
_, _ = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
561+
_, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
586562
Name: "test_function1",
587563
})
588564
}
@@ -645,15 +621,7 @@ func TestMuxServerGetFunctionServer_GetMetadata_Duplicate(t *testing.T) {
645621
terraformOp := func() {
646622
defer wg.Done()
647623

648-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
649-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
650-
651-
if !ok {
652-
t.Error("muxServer should implement tfprotov5.FunctionServer")
653-
}
654-
655-
// resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
656-
resp, _ := functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
624+
resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
657625
Name: "test_function",
658626
})
659627

@@ -715,15 +683,7 @@ func TestMuxServerGetFunctionServer_GetMetadata_Partial(t *testing.T) {
715683
terraformOp := func() {
716684
defer wg.Done()
717685

718-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
719-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
720-
721-
if !ok {
722-
t.Error("muxServer should implement tfprotov5.FunctionServer")
723-
}
724-
725-
// _, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
726-
_, _ = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
686+
_, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
727687
Name: "test_function1",
728688
})
729689
}
@@ -785,15 +745,7 @@ func TestMuxServerGetFunctionServer_Missing(t *testing.T) {
785745
terraformOp := func() {
786746
defer wg.Done()
787747

788-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
789-
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)
790-
791-
if !ok {
792-
t.Error("muxServer should implement tfprotov5.FunctionServer")
793-
}
794-
795-
// resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
796-
resp, _ := functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
748+
resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
797749
Name: "test_function_nonexistent",
798750
})
799751

tf5to6server/tf5to6server.go

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ func UpgradeServer(_ context.Context, v5server func() tfprotov5.ProviderServer)
2929

3030
var _ tfprotov6.ProviderServer = v5tov6Server{}
3131

32-
// Temporarily verify that v5tov6Server implements new RPCs correctly.
33-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
34-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
35-
var (
36-
_ tfprotov6.FunctionServer = v5tov6Server{}
37-
//nolint:staticcheck // Intentional verification of interface implementation.
38-
_ tfprotov6.ResourceServerWithMoveResourceState = v5tov6Server{}
39-
)
40-
4132
type v5tov6Server struct {
4233
v5Server tfprotov5.ProviderServer
4334
}
@@ -54,26 +45,9 @@ func (s v5tov6Server) ApplyResourceChange(ctx context.Context, req *tfprotov6.Ap
5445
}
5546

5647
func (s v5tov6Server) CallFunction(ctx context.Context, req *tfprotov6.CallFunctionRequest) (*tfprotov6.CallFunctionResponse, error) {
57-
// Remove and call s.v5Server.CallFunction below directly.
58-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
59-
functionServer, ok := s.v5Server.(tfprotov5.FunctionServer)
60-
61-
if !ok {
62-
v6Resp := &tfprotov6.CallFunctionResponse{
63-
Error: &tfprotov6.FunctionError{
64-
Text: "Provider Functions Not Implemented: A provider-defined function call was received by the provider, however the provider does not implement functions. " +
65-
"Either upgrade the provider to a version that implements provider-defined functions or this is a bug in Terraform that should be reported to the Terraform maintainers.",
66-
},
67-
}
68-
69-
return v6Resp, nil
70-
}
71-
7248
v5Req := tfprotov6tov5.CallFunctionRequest(req)
73-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
74-
// v5Resp, err := s.v5Server.CallFunction(ctx, v5Req)
75-
v5Resp, err := functionServer.CallFunction(ctx, v5Req)
7649

50+
v5Resp, err := s.v5Server.CallFunction(ctx, v5Req)
7751
if err != nil {
7852
return nil, err
7953
}
@@ -93,23 +67,9 @@ func (s v5tov6Server) ConfigureProvider(ctx context.Context, req *tfprotov6.Conf
9367
}
9468

9569
func (s v5tov6Server) GetFunctions(ctx context.Context, req *tfprotov6.GetFunctionsRequest) (*tfprotov6.GetFunctionsResponse, error) {
96-
// Remove and call s.v5Server.GetFunctions below directly.
97-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
98-
functionServer, ok := s.v5Server.(tfprotov5.FunctionServer)
99-
100-
if !ok {
101-
v6Resp := &tfprotov6.GetFunctionsResponse{
102-
Functions: map[string]*tfprotov6.Function{},
103-
}
104-
105-
return v6Resp, nil
106-
}
107-
10870
v5Req := tfprotov6tov5.GetFunctionsRequest(req)
109-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
110-
// v5Resp, err := s.v5Server.GetFunctions(ctx, v5Req)
111-
v5Resp, err := functionServer.GetFunctions(ctx, v5Req)
11271

72+
v5Resp, err := s.v5Server.GetFunctions(ctx, v5Req)
11373
if err != nil {
11474
return nil, err
11575
}
@@ -151,31 +111,9 @@ func (s v5tov6Server) ImportResourceState(ctx context.Context, req *tfprotov6.Im
151111
}
152112

153113
func (s v5tov6Server) MoveResourceState(ctx context.Context, req *tfprotov6.MoveResourceStateRequest) (*tfprotov6.MoveResourceStateResponse, error) {
154-
// Remove and call s.v5Server.MoveResourceState below directly.
155-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
156-
//nolint:staticcheck // Intentional verification of interface implementation.
157-
resourceServer, ok := s.v5Server.(tfprotov5.ResourceServerWithMoveResourceState)
158-
159-
if !ok {
160-
v6Resp := &tfprotov6.MoveResourceStateResponse{
161-
Diagnostics: []*tfprotov6.Diagnostic{
162-
{
163-
Severity: tfprotov6.DiagnosticSeverityError,
164-
Summary: "MoveResourceState Not Implemented",
165-
Detail: "A MoveResourceState call was received by the provider, however the provider does not implement the RPC. " +
166-
"Either upgrade the provider to a version that implements MoveResourceState or this is a bug in Terraform that should be reported to the Terraform maintainers.",
167-
},
168-
},
169-
}
170-
171-
return v6Resp, nil
172-
}
173-
174114
v5Req := tfprotov6tov5.MoveResourceStateRequest(req)
175-
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
176-
// v5Resp, err := s.v5Server.MoveResourceState(ctx, v5Req)
177-
v5Resp, err := resourceServer.MoveResourceState(ctx, v5Req)
178115

116+
v5Resp, err := s.v5Server.MoveResourceState(ctx, v5Req)
179117
if err != nil {
180118
return nil, err
181119
}

0 commit comments

Comments
 (0)