Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: Initial provider defined functions implementation #1288

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changes/unreleased/NOTES-20231107-141609.yaml
Original file line number Diff line number Diff line change
@@ -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"
32 changes: 32 additions & 0 deletions helper/schema/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand All @@ -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(),
}
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions helper/schema/grpc_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
TypeName: "test_datasource2",
},
},
Functions: []tfprotov5.FunctionMetadata{},
Resources: []tfprotov5.ResourceMetadata{},
ServerCapabilities: &tfprotov5.ServerCapabilities{
GetProviderSchemaOptional: true,
Expand All @@ -2137,6 +2138,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
TypeName: "test_datasource2",
},
},
Functions: []tfprotov5.FunctionMetadata{},
Resources: []tfprotov5.ResourceMetadata{
{
TypeName: "test_resource1",
Expand All @@ -2159,6 +2161,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
},
Expected: &tfprotov5.GetMetadataResponse{
DataSources: []tfprotov5.DataSourceMetadata{},
Functions: []tfprotov5.FunctionMetadata{},
Resources: []tfprotov5.ResourceMetadata{
{
TypeName: "test_resource1",
Expand Down