Skip to content

Commit

Permalink
tfprotov5+tfprotov6: Require FunctionServer in ProviderServer
Browse files Browse the repository at this point in the history
Reference: #353

This breaking change aligns the `tfprotov5` and `tfprotov6` packages with the intended design of this Go module, which is to fully implement the Terraform Plugin Protocol. The `FunctionServer` interface was temporarily optional in v0.20.0 so downstream SDKs could implement and release support first with a lesser likelihood that developers would run into compilation errors when only upgrading a single downstream Go module.

Provider developers should upgrade this Go module only after ensuring their provider Go module is using at least:

- github.com/hashicorp/[email protected]
- github.com/hashicorp/[email protected]
- github.com/hashicorp/terraform-plugin-sdk/[email protected]
  • Loading branch information
bflad committed Dec 14, 2023
1 parent 4eb19ff commit 78337ba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 94 deletions.
8 changes: 8 additions & 0 deletions .changes/unreleased/BREAKING CHANGES-20231214-105454.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: BREAKING CHANGES
body: 'tfprotov5+tfprotov6: The `ProviderServer` interface now requires the `FunctionServer`
interface. Before upgrading this Go module, ensure you are depending on at least
terraform-plugin-framework v1.5.0, terraform-plugin-mux v0.13.0, and
terraform-plugin-sdk/v2 v2.31.0.'
time: 2023-12-14T10:54:54.463017-05:00
custom:
Issue: "353"
5 changes: 1 addition & 4 deletions tfprotov5/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ type ProviderServer interface {
// are a handy interface for defining what a function is to
// terraform-plugin-go, so they are their own interface that is composed
// into ProviderServer.
//
// This will be required in an upcoming release.
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
// FunctionServer
FunctionServer
}

// GetMetadataRequest represents a GetMetadata RPC request.
Expand Down
45 changes: 2 additions & 43 deletions tfprotov5/tf5server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,28 +912,6 @@ func (s *server) CallFunction(ctx context.Context, protoReq *tfplugin5.CallFunct
logging.ProtocolTrace(ctx, "Received request")
defer logging.ProtocolTrace(ctx, "Served request")

// Remove this check and error in preference of s.downstream.CallFunction
// below once ProviderServer interface requires FunctionServer.
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
functionServer, ok := s.downstream.(tfprotov5.FunctionServer)

if !ok {
logging.ProtocolError(ctx, "ProviderServer does not implement FunctionServer")

protoResp := &tfplugin5.CallFunction_Response{
Diagnostics: []*tfplugin5.Diagnostic{
{
Severity: tfplugin5.Diagnostic_ERROR,
Summary: "Provider Functions Not Implemented",
Detail: "A provider-defined function call was received by the provider, however the provider does not implement functions. " +
"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.",
},
},
}

return protoResp, nil
}

req, err := fromproto.CallFunctionRequest(protoReq)

if err != nil {
Expand All @@ -948,9 +926,7 @@ func (s *server) CallFunction(ctx context.Context, protoReq *tfplugin5.CallFunct

ctx = tf5serverlogging.DownstreamRequest(ctx)

// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
// resp, err := s.downstream.CallFunction(ctx, req)
resp, err := functionServer.CallFunction(ctx, req)
resp, err := s.downstream.CallFunction(ctx, req)

if err != nil {
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
Expand Down Expand Up @@ -978,21 +954,6 @@ func (s *server) GetFunctions(ctx context.Context, protoReq *tfplugin5.GetFuncti
logging.ProtocolTrace(ctx, "Received request")
defer logging.ProtocolTrace(ctx, "Served request")

// Remove this check and response in preference of s.downstream.GetFunctions
// below once ProviderServer interface requires FunctionServer.
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
functionServer, ok := s.downstream.(tfprotov5.FunctionServer)

if !ok {
logging.ProtocolWarn(ctx, "ProviderServer does not implement FunctionServer")

protoResp := &tfplugin5.GetFunctions_Response{
Functions: map[string]*tfplugin5.Function{},
}

return protoResp, nil
}

req, err := fromproto.GetFunctionsRequest(protoReq)

if err != nil {
Expand All @@ -1003,9 +964,7 @@ func (s *server) GetFunctions(ctx context.Context, protoReq *tfplugin5.GetFuncti

ctx = tf5serverlogging.DownstreamRequest(ctx)

// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
// resp, err := s.downstream.GetFunctions(ctx, req)
resp, err := functionServer.GetFunctions(ctx, req)
resp, err := s.downstream.GetFunctions(ctx, req)

if err != nil {
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
Expand Down
5 changes: 1 addition & 4 deletions tfprotov6/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ type ProviderServer interface {
// are a handy interface for defining what a function is to
// terraform-plugin-go, so they are their own interface that is composed
// into ProviderServer.
//
// This will be required in an upcoming release.
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
// FunctionServer
FunctionServer
}

// GetMetadataRequest represents a GetMetadata RPC request.
Expand Down
45 changes: 2 additions & 43 deletions tfprotov6/tf6server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,28 +910,6 @@ func (s *server) CallFunction(ctx context.Context, protoReq *tfplugin6.CallFunct
logging.ProtocolTrace(ctx, "Received request")
defer logging.ProtocolTrace(ctx, "Served request")

// Remove this check and error in preference of s.downstream.CallFunction
// below once ProviderServer interface requires FunctionServer.
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
functionServer, ok := s.downstream.(tfprotov6.FunctionServer)

if !ok {
logging.ProtocolError(ctx, "ProviderServer does not implement FunctionServer")

protoResp := &tfplugin6.CallFunction_Response{
Diagnostics: []*tfplugin6.Diagnostic{
{
Severity: tfplugin6.Diagnostic_ERROR,
Summary: "Provider Functions Not Implemented",
Detail: "A provider-defined function call was received by the provider, however the provider does not implement functions. " +
"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.",
},
},
}

return protoResp, nil
}

req, err := fromproto.CallFunctionRequest(protoReq)

if err != nil {
Expand All @@ -946,9 +924,7 @@ func (s *server) CallFunction(ctx context.Context, protoReq *tfplugin6.CallFunct

ctx = tf6serverlogging.DownstreamRequest(ctx)

// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
// resp, err := s.downstream.CallFunction(ctx, req)
resp, err := functionServer.CallFunction(ctx, req)
resp, err := s.downstream.CallFunction(ctx, req)

if err != nil {
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
Expand Down Expand Up @@ -976,21 +952,6 @@ func (s *server) GetFunctions(ctx context.Context, protoReq *tfplugin6.GetFuncti
logging.ProtocolTrace(ctx, "Received request")
defer logging.ProtocolTrace(ctx, "Served request")

// Remove this check and response in preference of s.downstream.GetFunctions
// below once ProviderServer interface requires FunctionServer.
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
functionServer, ok := s.downstream.(tfprotov6.FunctionServer)

if !ok {
logging.ProtocolWarn(ctx, "ProviderServer does not implement FunctionServer")

protoResp := &tfplugin6.GetFunctions_Response{
Functions: map[string]*tfplugin6.Function{},
}

return protoResp, nil
}

req, err := fromproto.GetFunctionsRequest(protoReq)

if err != nil {
Expand All @@ -1001,9 +962,7 @@ func (s *server) GetFunctions(ctx context.Context, protoReq *tfplugin6.GetFuncti

ctx = tf6serverlogging.DownstreamRequest(ctx)

// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
// resp, err := s.downstream.GetFunctions(ctx, req)
resp, err := functionServer.GetFunctions(ctx, req)
resp, err := s.downstream.GetFunctions(ctx, req)

if err != nil {
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
Expand Down

0 comments on commit 78337ba

Please sign in to comment.