Skip to content

Commit fb1d856

Browse files
committed
tfprotov5+tfprotov6: Make FunctionServer implementation optional
Reference: #353
1 parent 2017fc8 commit fb1d856

File tree

7 files changed

+98
-17
lines changed

7 files changed

+98
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
kind: FEATURES
2-
body: 'tfprotov5: Upgraded protocol to 5.5, which implements support for provider
3-
defined functions'
2+
body: 'tfprotov5+tfprotov6: Upgraded protocols and added types to support
3+
provider-defined functions'
44
time: 2023-10-26T16:43:00.024481-04:00
55
custom:
66
Issue: "351"

.changes/unreleased/FEATURES-20231026-164327.yaml

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
kind: NOTES
2-
body: 'all: If using terraform-plugin-framework, terraform-plugin-mux, or terraform-plugin-sdk,
3-
only upgrade this Go module as part of upgrading those Go modules or you may receive
4-
a `missing method CallFunction` or `missing method GetFunctions` error when compiling'
2+
body: 'tfprotov5+tfprotov6: An upcoming release will require the FunctionServer
3+
implementation as part of ProviderServer.'
54
time: 2023-10-26T16:43:59.845786-04:00
65
custom:
76
Issue: "351"

tfprotov5/provider.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ 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-
FunctionServer
56+
//
57+
// This will be required in an upcoming release.
58+
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
59+
// FunctionServer
5760
}
5861

5962
// GetMetadataRequest represents a GetMetadata RPC request.

tfprotov5/tf5server/server.go

+43-2
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,28 @@ 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+
915937
req, err := fromproto.CallFunctionRequest(protoReq)
916938

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

927949
ctx = tf5serverlogging.DownstreamRequest(ctx)
928950

929-
resp, err := s.downstream.CallFunction(ctx, req)
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)
930954

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

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+
957996
req, err := fromproto.GetFunctionsRequest(protoReq)
958997

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

9651004
ctx = tf5serverlogging.DownstreamRequest(ctx)
9661005

967-
resp, err := s.downstream.GetFunctions(ctx, req)
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)
9681009

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

tfprotov6/provider.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ 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-
FunctionServer
56+
//
57+
// This will be required in an upcoming release.
58+
// Reference: https://github.com/hashicorp/terraform-plugin-go/issues/353
59+
// FunctionServer
5760
}
5861

5962
// GetMetadataRequest represents a GetMetadata RPC request.

tfprotov6/tf6server/server.go

+43-2
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,28 @@ 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+
913935
req, err := fromproto.CallFunctionRequest(protoReq)
914936

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

925947
ctx = tf6serverlogging.DownstreamRequest(ctx)
926948

927-
resp, err := s.downstream.CallFunction(ctx, req)
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)
928952

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

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+
955994
req, err := fromproto.GetFunctionsRequest(protoReq)
956995

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

9631002
ctx = tf6serverlogging.DownstreamRequest(ctx)
9641003

965-
resp, err := s.downstream.GetFunctions(ctx, req)
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)
9661007

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

0 commit comments

Comments
 (0)