diff --git a/.changes/unreleased/NOTES-20231107-141609.yaml b/.changes/unreleased/NOTES-20231107-141609.yaml new file mode 100644 index 0000000000..abee4f0952 --- /dev/null +++ b/.changes/unreleased/NOTES-20231107-141609.yaml @@ -0,0 +1,8 @@ +kind: NOTES +body: 'helper/schema: While this Go module will not receive support for + provider-defined functions, the provider server is updated to handle the new + operations, which will be required to prevent errors when updating + terraform-plugin-framework or terraform-plugin-mux in the future.' +time: 2023-11-07T14:16:09.783296-05:00 +custom: + Issue: "1288" diff --git a/helper/schema/grpc_provider.go b/helper/schema/grpc_provider.go index 287914683f..4ba774a1f2 100644 --- a/helper/schema/grpc_provider.go +++ b/helper/schema/grpc_provider.go @@ -80,6 +80,7 @@ func (s *GRPCProviderServer) GetMetadata(ctx context.Context, req *tfprotov5.Get resp := &tfprotov5.GetMetadataResponse{ DataSources: make([]tfprotov5.DataSourceMetadata, 0, len(s.provider.DataSourcesMap)), + Functions: make([]tfprotov5.FunctionMetadata, 0), Resources: make([]tfprotov5.ResourceMetadata, 0, len(s.provider.ResourcesMap)), ServerCapabilities: s.serverCapabilities(), } @@ -106,6 +107,7 @@ func (s *GRPCProviderServer) GetProviderSchema(ctx context.Context, req *tfproto resp := &tfprotov5.GetProviderSchemaResponse{ DataSourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.DataSourcesMap)), + Functions: make(map[string]*tfprotov5.Function, 0), ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)), ServerCapabilities: s.serverCapabilities(), } @@ -1271,6 +1273,36 @@ func (s *GRPCProviderServer) ReadDataSource(ctx context.Context, req *tfprotov5. return resp, nil } +func (s *GRPCProviderServer) CallFunction(ctx context.Context, req *tfprotov5.CallFunctionRequest) (*tfprotov5.CallFunctionResponse, error) { + ctx = logging.InitContext(ctx) + + logging.HelperSchemaTrace(ctx, "Returning error for provider function call") + + resp := &tfprotov5.CallFunctionResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "Function Not Found", + Detail: fmt.Sprintf("No function named %q was found in the provider.", req.Name), + }, + }, + } + + return resp, nil +} + +func (s *GRPCProviderServer) GetFunctions(ctx context.Context, req *tfprotov5.GetFunctionsRequest) (*tfprotov5.GetFunctionsResponse, error) { + ctx = logging.InitContext(ctx) + + logging.HelperSchemaTrace(ctx, "Getting provider functions") + + resp := &tfprotov5.GetFunctionsResponse{ + Functions: make(map[string]*tfprotov5.Function, 0), + } + + return resp, nil +} + func pathToAttributePath(path cty.Path) *tftypes.AttributePath { var steps []tftypes.AttributePathStep diff --git a/helper/schema/grpc_provider_test.go b/helper/schema/grpc_provider_test.go index e873084dcc..537d8fa1c8 100644 --- a/helper/schema/grpc_provider_test.go +++ b/helper/schema/grpc_provider_test.go @@ -2111,6 +2111,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) { TypeName: "test_datasource2", }, }, + Functions: []tfprotov5.FunctionMetadata{}, Resources: []tfprotov5.ResourceMetadata{}, ServerCapabilities: &tfprotov5.ServerCapabilities{ GetProviderSchemaOptional: true, @@ -2137,6 +2138,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) { TypeName: "test_datasource2", }, }, + Functions: []tfprotov5.FunctionMetadata{}, Resources: []tfprotov5.ResourceMetadata{ { TypeName: "test_resource1", @@ -2159,6 +2161,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) { }, Expected: &tfprotov5.GetMetadataResponse{ DataSources: []tfprotov5.DataSourceMetadata{}, + Functions: []tfprotov5.FunctionMetadata{}, Resources: []tfprotov5.ResourceMetadata{ { TypeName: "test_resource1",