Skip to content

Commit

Permalink
all: Remove ResourceServerWithMoveResourceState type assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
austinvalle committed May 8, 2024
1 parent 74edfc2 commit a5e8fc5
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 163 deletions.
7 changes: 0 additions & 7 deletions tf5muxserver/mux_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import (

var _ tfprotov5.ProviderServer = &muxServer{}

// Temporarily verify that v5tov6Server implements new RPCs correctly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
var (
//nolint:staticcheck // Intentional verification of interface implementation.
_ tfprotov5.ResourceServerWithMoveResourceState = &muxServer{}
)

// muxServer is a gRPC server implementation that stands in front of other
// gRPC servers, routing requests to them as if they were a single server. It
// should always be instantiated by calling NewMuxServer().
Expand Down
24 changes: 1 addition & 23 deletions tf5muxserver/mux_server_MoveResourceState.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,7 @@ func (s *muxServer) MoveResourceState(ctx context.Context, req *tfprotov5.MoveRe
}

ctx = logging.Tfprotov5ProviderServerContext(ctx, server)

// Remove and call server.MoveResourceState below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentionally verifying interface implementation
resourceServer, ok := server.(tfprotov5.ResourceServerWithMoveResourceState)

if !ok {
resp := &tfprotov5.MoveResourceStateResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "MoveResourceState Not Implemented",
Detail: "A MoveResourceState call was received by the provider, however the provider does not implement MoveResourceState. " +
"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.",
},
},
}

return resp, nil
}

logging.MuxTrace(ctx, "calling downstream server")

// return server.MoveResourceState(ctx, req)
return resourceServer.MoveResourceState(ctx, req)
return server.MoveResourceState(ctx, req)
}
14 changes: 2 additions & 12 deletions tf5muxserver/mux_server_MoveResourceState_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,7 @@ func TestMuxServerMoveResourceState(t *testing.T) {
t.Fatalf("unexpected error setting up factory: %s", err)
}

// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentionally verifying interface implementation
resourceServer, ok := muxServer.ProviderServer().(tfprotov5.ResourceServerWithMoveResourceState)

if !ok {
t.Fatal("muxServer should implement tfprotov5.ResourceServerWithMoveResourceState")
}

// _, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
_, err = resourceServer.MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
_, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
TargetTypeName: "test_resource1",
})

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

// _, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
_, err = resourceServer.MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
_, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
TargetTypeName: "test_resource2",
})

Expand Down
31 changes: 1 addition & 30 deletions tf5to6server/tf5to6server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ func UpgradeServer(_ context.Context, v5server func() tfprotov5.ProviderServer)

var _ tfprotov6.ProviderServer = v5tov6Server{}

// Temporarily verify that v5tov6Server implements new RPCs correctly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
var (
//nolint:staticcheck // Intentional verification of interface implementation.
_ tfprotov6.ResourceServerWithMoveResourceState = v5tov6Server{}
)

type v5tov6Server struct {
v5Server tfprotov5.ProviderServer
}
Expand Down Expand Up @@ -118,31 +111,9 @@ func (s v5tov6Server) ImportResourceState(ctx context.Context, req *tfprotov6.Im
}

func (s v5tov6Server) MoveResourceState(ctx context.Context, req *tfprotov6.MoveResourceStateRequest) (*tfprotov6.MoveResourceStateResponse, error) {
// Remove and call s.v5Server.MoveResourceState below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentional verification of interface implementation.
resourceServer, ok := s.v5Server.(tfprotov5.ResourceServerWithMoveResourceState)

if !ok {
v6Resp := &tfprotov6.MoveResourceStateResponse{
Diagnostics: []*tfprotov6.Diagnostic{
{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "MoveResourceState Not Implemented",
Detail: "A MoveResourceState call was received by the provider, however the provider does not implement the RPC. " +
"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.",
},
},
}

return v6Resp, nil
}

v5Req := tfprotov6tov5.MoveResourceStateRequest(req)
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
// v5Resp, err := s.v5Server.MoveResourceState(ctx, v5Req)
v5Resp, err := resourceServer.MoveResourceState(ctx, v5Req)

v5Resp, err := s.v5Server.MoveResourceState(ctx, v5Req)
if err != nil {
return nil, err
}
Expand Down
11 changes: 1 addition & 10 deletions tf5to6server/tf5to6server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,7 @@ func TestV5ToV6ServerMoveResourceState(t *testing.T) {
t.Fatalf("unexpected error downgrading server: %s", err)
}

// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentional verification of interface implementation.
resourceServer, ok := v6server.(tfprotov6.ResourceServerWithMoveResourceState)

if !ok {
t.Fatal("v5server should implement tfprotov6.ResourceServerWithMoveResourceState")
}

// _, err = v6server.MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
_, err = resourceServer.MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
_, err = v6server.MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
TargetTypeName: "test_resource",
})

Expand Down
7 changes: 0 additions & 7 deletions tf6muxserver/mux_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import (

var _ tfprotov6.ProviderServer = &muxServer{}

// Temporarily verify that v5tov6Server implements new RPCs correctly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
var (
//nolint:staticcheck // Intentional verification of interface implementation.
_ tfprotov6.ResourceServerWithMoveResourceState = &muxServer{}
)

// muxServer is a gRPC server implementation that stands in front of other
// gRPC servers, routing requests to them as if they were a single server. It
// should always be instantiated by calling NewMuxServer().
Expand Down
23 changes: 1 addition & 22 deletions tf6muxserver/mux_server_MoveResourceState.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,7 @@ func (s *muxServer) MoveResourceState(ctx context.Context, req *tfprotov6.MoveRe

ctx = logging.Tfprotov6ProviderServerContext(ctx, server)

// Remove and call server.MoveResourceState below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentionally verifying interface implementation
resourceServer, ok := server.(tfprotov6.ResourceServerWithMoveResourceState)

if !ok {
resp := &tfprotov6.MoveResourceStateResponse{
Diagnostics: []*tfprotov6.Diagnostic{
{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "MoveResourceState Not Implemented",
Detail: "A MoveResourceState call was received by the provider, however the provider does not implement MoveResourceState. " +
"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.",
},
},
}

return resp, nil
}

logging.MuxTrace(ctx, "calling downstream server")

// return server.MoveResourceState(ctx, req)
return resourceServer.MoveResourceState(ctx, req)
return server.MoveResourceState(ctx, req)
}
14 changes: 2 additions & 12 deletions tf6muxserver/mux_server_MoveResourceState_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,7 @@ func TestMuxServerMoveResourceState(t *testing.T) {
t.Fatalf("unexpected error setting up factory: %s", err)
}

// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentionally verifying interface implementation
resourceServer, ok := muxServer.ProviderServer().(tfprotov6.ResourceServerWithMoveResourceState)

if !ok {
t.Fatal("muxServer should implement tfprotov6.ResourceServerWithMoveResourceState")
}

// _, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
_, err = resourceServer.MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
_, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
TargetTypeName: "test_resource1",
})

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

// _, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
_, err = resourceServer.MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
_, err = muxServer.ProviderServer().MoveResourceState(ctx, &tfprotov6.MoveResourceStateRequest{
TargetTypeName: "test_resource2",
})

Expand Down
31 changes: 1 addition & 30 deletions tf6to5server/tf6to5server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func DowngradeServer(ctx context.Context, v6server func() tfprotov6.ProviderServ

var _ tfprotov5.ProviderServer = v6tov5Server{}

// Temporarily verify that v6tov5Server implements new RPCs correctly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
var (
//nolint:staticcheck // Intentional verification of interface implementation.
_ tfprotov5.ResourceServerWithMoveResourceState = v6tov5Server{}
)

type v6tov5Server struct {
v6Server tfprotov6.ProviderServer
}
Expand Down Expand Up @@ -130,31 +123,9 @@ func (s v6tov5Server) ImportResourceState(ctx context.Context, req *tfprotov5.Im
}

func (s v6tov5Server) MoveResourceState(ctx context.Context, req *tfprotov5.MoveResourceStateRequest) (*tfprotov5.MoveResourceStateResponse, error) {
// Remove and call s.v6Server.MoveResourceState below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentional verification of interface implementation.
resourceServer, ok := s.v6Server.(tfprotov6.ResourceServerWithMoveResourceState)

if !ok {
v5Resp := &tfprotov5.MoveResourceStateResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "MoveResourceState Not Implemented",
Detail: "A MoveResourceState call was received by the provider, however the provider does not implement the RPC. " +
"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.",
},
},
}

return v5Resp, nil
}

v6Req := tfprotov5tov6.MoveResourceStateRequest(req)
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
// v6Resp, err := s.v6Server.MoveResourceState(ctx, v6Req)
v6Resp, err := resourceServer.MoveResourceState(ctx, v6Req)

v6Resp, err := s.v6Server.MoveResourceState(ctx, v6Req)
if err != nil {
return nil, err
}
Expand Down
11 changes: 1 addition & 10 deletions tf6to5server/tf6to5server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,7 @@ func TestV6ToV5ServerMoveResourceState(t *testing.T) {
t.Fatalf("unexpected error downgrading server: %s", err)
}

// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/219
//nolint:staticcheck // Intentional verification of interface implementation.
resourceServer, ok := v5server.(tfprotov5.ResourceServerWithMoveResourceState)

if !ok {
t.Fatal("v5server should implement tfprotov5.ResourceServerWithMoveResourceState")
}

// _, err = v5server.MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
_, err = resourceServer.MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
_, err = v5server.MoveResourceState(ctx, &tfprotov5.MoveResourceStateRequest{
TargetTypeName: "test_resource",
})

Expand Down

0 comments on commit a5e8fc5

Please sign in to comment.