Skip to content

Commit 78337ba

Browse files
committed
tfprotov5+tfprotov6: Require FunctionServer in ProviderServer
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]
1 parent 4eb19ff commit 78337ba

File tree

5 files changed

+14
-94
lines changed

5 files changed

+14
-94
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
kind: BREAKING CHANGES
2+
body: 'tfprotov5+tfprotov6: The `ProviderServer` interface now requires the `FunctionServer`
3+
interface. Before upgrading this Go module, ensure you are depending on at least
4+
terraform-plugin-framework v1.5.0, terraform-plugin-mux v0.13.0, and
5+
terraform-plugin-sdk/v2 v2.31.0.'
6+
time: 2023-12-14T10:54:54.463017-05:00
7+
custom:
8+
Issue: "353"

tfprotov5/provider.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ type ProviderServer interface {
5353
// are a handy interface for defining what a function is to
5454
// terraform-plugin-go, so they are their own interface that is composed
5555
// into ProviderServer.
56-
//
57-
// This will be required in an upcoming release.
58-
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
59-
// FunctionServer
56+
FunctionServer
6057
}
6158

6259
// GetMetadataRequest represents a GetMetadata RPC request.

tfprotov5/tf5server/server.go

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -912,28 +912,6 @@ func (s *server) CallFunction(ctx context.Context, protoReq *tfplugin5.CallFunct
912912
logging.ProtocolTrace(ctx, "Received request")
913913
defer logging.ProtocolTrace(ctx, "Served request")
914914

915-
// Remove this check and error in preference of s.downstream.CallFunction
916-
// below once ProviderServer interface requires FunctionServer.
917-
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
918-
functionServer, ok := s.downstream.(tfprotov5.FunctionServer)
919-
920-
if !ok {
921-
logging.ProtocolError(ctx, "ProviderServer does not implement FunctionServer")
922-
923-
protoResp := &tfplugin5.CallFunction_Response{
924-
Diagnostics: []*tfplugin5.Diagnostic{
925-
{
926-
Severity: tfplugin5.Diagnostic_ERROR,
927-
Summary: "Provider Functions Not Implemented",
928-
Detail: "A provider-defined function call was received by the provider, however the provider does not implement functions. " +
929-
"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.",
930-
},
931-
},
932-
}
933-
934-
return protoResp, nil
935-
}
936-
937915
req, err := fromproto.CallFunctionRequest(protoReq)
938916

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

949927
ctx = tf5serverlogging.DownstreamRequest(ctx)
950928

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

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

981-
// Remove this check and response in preference of s.downstream.GetFunctions
982-
// below once ProviderServer interface requires FunctionServer.
983-
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
984-
functionServer, ok := s.downstream.(tfprotov5.FunctionServer)
985-
986-
if !ok {
987-
logging.ProtocolWarn(ctx, "ProviderServer does not implement FunctionServer")
988-
989-
protoResp := &tfplugin5.GetFunctions_Response{
990-
Functions: map[string]*tfplugin5.Function{},
991-
}
992-
993-
return protoResp, nil
994-
}
995-
996957
req, err := fromproto.GetFunctionsRequest(protoReq)
997958

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

1004965
ctx = tf5serverlogging.DownstreamRequest(ctx)
1005966

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

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

tfprotov6/provider.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ type ProviderServer interface {
5353
// are a handy interface for defining what a function is to
5454
// terraform-plugin-go, so they are their own interface that is composed
5555
// into ProviderServer.
56-
//
57-
// This will be required in an upcoming release.
58-
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
59-
// FunctionServer
56+
FunctionServer
6057
}
6158

6259
// GetMetadataRequest represents a GetMetadata RPC request.

tfprotov6/tf6server/server.go

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -910,28 +910,6 @@ func (s *server) CallFunction(ctx context.Context, protoReq *tfplugin6.CallFunct
910910
logging.ProtocolTrace(ctx, "Received request")
911911
defer logging.ProtocolTrace(ctx, "Served request")
912912

913-
// Remove this check and error in preference of s.downstream.CallFunction
914-
// below once ProviderServer interface requires FunctionServer.
915-
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
916-
functionServer, ok := s.downstream.(tfprotov6.FunctionServer)
917-
918-
if !ok {
919-
logging.ProtocolError(ctx, "ProviderServer does not implement FunctionServer")
920-
921-
protoResp := &tfplugin6.CallFunction_Response{
922-
Diagnostics: []*tfplugin6.Diagnostic{
923-
{
924-
Severity: tfplugin6.Diagnostic_ERROR,
925-
Summary: "Provider Functions Not Implemented",
926-
Detail: "A provider-defined function call was received by the provider, however the provider does not implement functions. " +
927-
"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.",
928-
},
929-
},
930-
}
931-
932-
return protoResp, nil
933-
}
934-
935913
req, err := fromproto.CallFunctionRequest(protoReq)
936914

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

947925
ctx = tf6serverlogging.DownstreamRequest(ctx)
948926

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

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

979-
// Remove this check and response in preference of s.downstream.GetFunctions
980-
// below once ProviderServer interface requires FunctionServer.
981-
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
982-
functionServer, ok := s.downstream.(tfprotov6.FunctionServer)
983-
984-
if !ok {
985-
logging.ProtocolWarn(ctx, "ProviderServer does not implement FunctionServer")
986-
987-
protoResp := &tfplugin6.GetFunctions_Response{
988-
Functions: map[string]*tfplugin6.Function{},
989-
}
990-
991-
return protoResp, nil
992-
}
993-
994955
req, err := fromproto.GetFunctionsRequest(protoReq)
995956

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

1002963
ctx = tf6serverlogging.DownstreamRequest(ctx)
1003964

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

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

0 commit comments

Comments
 (0)