diff --git a/.changes/unreleased/NOTES-20250916-124728.yaml b/.changes/unreleased/NOTES-20250916-124728.yaml new file mode 100644 index 0000000000..64601ed987 --- /dev/null +++ b/.changes/unreleased/NOTES-20250916-124728.yaml @@ -0,0 +1,5 @@ +kind: NOTES +body: 'helper/schema: Update the provider server to handle Action RPCs by returning an error since they are not supported by SDKv2.' +time: 2025-09-16T12:47:28.705896-04:00 +custom: + Issue: "1522" diff --git a/helper/schema/grpc_provider.go b/helper/schema/grpc_provider.go index 937fe9b9b6..3202c504ca 100644 --- a/helper/schema/grpc_provider.go +++ b/helper/schema/grpc_provider.go @@ -198,6 +198,7 @@ func (s *GRPCProviderServer) GetMetadata(ctx context.Context, req *tfprotov5.Get EphemeralResources: make([]tfprotov5.EphemeralResourceMetadata, 0), Functions: make([]tfprotov5.FunctionMetadata, 0), ListResources: make([]tfprotov5.ListResourceMetadata, 0), + Actions: make([]tfprotov5.ActionMetadata, 0), Resources: make([]tfprotov5.ResourceMetadata, 0, len(s.provider.ResourcesMap)), ServerCapabilities: s.serverCapabilities(), } @@ -227,6 +228,7 @@ func (s *GRPCProviderServer) GetProviderSchema(ctx context.Context, req *tfproto EphemeralResourceSchemas: make(map[string]*tfprotov5.Schema, 0), Functions: make(map[string]*tfprotov5.Function, 0), ListResourceSchemas: make(map[string]*tfprotov5.Schema, 0), + ActionSchemas: make(map[string]*tfprotov5.ActionSchema, 0), ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)), ServerCapabilities: s.serverCapabilities(), } @@ -2065,6 +2067,68 @@ func (s *GRPCProviderServer) ListResource(ctx context.Context, req *tfprotov5.Li return resp, nil } +func (s *GRPCProviderServer) ValidateActionConfig(ctx context.Context, req *tfprotov5.ValidateActionConfigRequest) (*tfprotov5.ValidateActionConfigResponse, error) { + ctx = logging.InitContext(ctx) + + logging.HelperSchemaTrace(ctx, "Returning error for action type validate") + + resp := &tfprotov5.ValidateActionConfigResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "Unknown Action Type", + Detail: fmt.Sprintf("The %q action type is not supported by this provider.", req.ActionType), + }, + }, + } + + return resp, nil +} + +func (s *GRPCProviderServer) PlanAction(ctx context.Context, req *tfprotov5.PlanActionRequest) (*tfprotov5.PlanActionResponse, error) { + ctx = logging.InitContext(ctx) + + logging.HelperSchemaTrace(ctx, "Returning error for action type plan") + + resp := &tfprotov5.PlanActionResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "Unknown Action Type", + Detail: fmt.Sprintf("The %q action type is not supported by this provider.", req.ActionType), + }, + }, + } + + return resp, nil +} + +func (s *GRPCProviderServer) InvokeAction(ctx context.Context, req *tfprotov5.InvokeActionRequest) (*tfprotov5.InvokeActionServerStream, error) { + ctx = logging.InitContext(ctx) + + logging.HelperSchemaTrace(ctx, "Returning error for action invoke") + + event := make([]tfprotov5.InvokeActionEvent, 0) + + event = append(event, tfprotov5.InvokeActionEvent{ + Type: tfprotov5.CompletedInvokeActionEventType{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "Unknown Action Type", + Detail: fmt.Sprintf("The %q action type is not supported by this provider.", req.ActionType), + }, + }, + }, + }) + + resp := &tfprotov5.InvokeActionServerStream{ + Events: slices.Values(event), + } + + 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 cd022cf27c..df822c2b8a 100644 --- a/helper/schema/grpc_provider_test.go +++ b/helper/schema/grpc_provider_test.go @@ -3763,6 +3763,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) { Functions: []tfprotov5.FunctionMetadata{}, EphemeralResources: []tfprotov5.EphemeralResourceMetadata{}, ListResources: []tfprotov5.ListResourceMetadata{}, + Actions: []tfprotov5.ActionMetadata{}, Resources: []tfprotov5.ResourceMetadata{}, ServerCapabilities: &tfprotov5.ServerCapabilities{ GetProviderSchemaOptional: true, @@ -3792,6 +3793,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) { Functions: []tfprotov5.FunctionMetadata{}, EphemeralResources: []tfprotov5.EphemeralResourceMetadata{}, ListResources: []tfprotov5.ListResourceMetadata{}, + Actions: []tfprotov5.ActionMetadata{}, Resources: []tfprotov5.ResourceMetadata{ { TypeName: "test_resource1", @@ -3817,6 +3819,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) { Functions: []tfprotov5.FunctionMetadata{}, EphemeralResources: []tfprotov5.EphemeralResourceMetadata{}, ListResources: []tfprotov5.ListResourceMetadata{}, + Actions: []tfprotov5.ActionMetadata{}, Resources: []tfprotov5.ResourceMetadata{ { TypeName: "test_resource1",