Skip to content

Commit d8ee719

Browse files
authored
action: Implement error returning for action RPCs (#1522)
* implement RPCs * add changelog
1 parent 183e62b commit d8ee719

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: NOTES
2+
body: 'helper/schema: Update the provider server to handle Action RPCs by returning an error since they are not supported by SDKv2.'
3+
time: 2025-09-16T12:47:28.705896-04:00
4+
custom:
5+
Issue: "1522"

helper/schema/grpc_provider.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func (s *GRPCProviderServer) GetMetadata(ctx context.Context, req *tfprotov5.Get
198198
EphemeralResources: make([]tfprotov5.EphemeralResourceMetadata, 0),
199199
Functions: make([]tfprotov5.FunctionMetadata, 0),
200200
ListResources: make([]tfprotov5.ListResourceMetadata, 0),
201+
Actions: make([]tfprotov5.ActionMetadata, 0),
201202
Resources: make([]tfprotov5.ResourceMetadata, 0, len(s.provider.ResourcesMap)),
202203
ServerCapabilities: s.serverCapabilities(),
203204
}
@@ -227,6 +228,7 @@ func (s *GRPCProviderServer) GetProviderSchema(ctx context.Context, req *tfproto
227228
EphemeralResourceSchemas: make(map[string]*tfprotov5.Schema, 0),
228229
Functions: make(map[string]*tfprotov5.Function, 0),
229230
ListResourceSchemas: make(map[string]*tfprotov5.Schema, 0),
231+
ActionSchemas: make(map[string]*tfprotov5.ActionSchema, 0),
230232
ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)),
231233
ServerCapabilities: s.serverCapabilities(),
232234
}
@@ -2065,6 +2067,68 @@ func (s *GRPCProviderServer) ListResource(ctx context.Context, req *tfprotov5.Li
20652067
return resp, nil
20662068
}
20672069

2070+
func (s *GRPCProviderServer) ValidateActionConfig(ctx context.Context, req *tfprotov5.ValidateActionConfigRequest) (*tfprotov5.ValidateActionConfigResponse, error) {
2071+
ctx = logging.InitContext(ctx)
2072+
2073+
logging.HelperSchemaTrace(ctx, "Returning error for action type validate")
2074+
2075+
resp := &tfprotov5.ValidateActionConfigResponse{
2076+
Diagnostics: []*tfprotov5.Diagnostic{
2077+
{
2078+
Severity: tfprotov5.DiagnosticSeverityError,
2079+
Summary: "Unknown Action Type",
2080+
Detail: fmt.Sprintf("The %q action type is not supported by this provider.", req.ActionType),
2081+
},
2082+
},
2083+
}
2084+
2085+
return resp, nil
2086+
}
2087+
2088+
func (s *GRPCProviderServer) PlanAction(ctx context.Context, req *tfprotov5.PlanActionRequest) (*tfprotov5.PlanActionResponse, error) {
2089+
ctx = logging.InitContext(ctx)
2090+
2091+
logging.HelperSchemaTrace(ctx, "Returning error for action type plan")
2092+
2093+
resp := &tfprotov5.PlanActionResponse{
2094+
Diagnostics: []*tfprotov5.Diagnostic{
2095+
{
2096+
Severity: tfprotov5.DiagnosticSeverityError,
2097+
Summary: "Unknown Action Type",
2098+
Detail: fmt.Sprintf("The %q action type is not supported by this provider.", req.ActionType),
2099+
},
2100+
},
2101+
}
2102+
2103+
return resp, nil
2104+
}
2105+
2106+
func (s *GRPCProviderServer) InvokeAction(ctx context.Context, req *tfprotov5.InvokeActionRequest) (*tfprotov5.InvokeActionServerStream, error) {
2107+
ctx = logging.InitContext(ctx)
2108+
2109+
logging.HelperSchemaTrace(ctx, "Returning error for action invoke")
2110+
2111+
event := make([]tfprotov5.InvokeActionEvent, 0)
2112+
2113+
event = append(event, tfprotov5.InvokeActionEvent{
2114+
Type: tfprotov5.CompletedInvokeActionEventType{
2115+
Diagnostics: []*tfprotov5.Diagnostic{
2116+
{
2117+
Severity: tfprotov5.DiagnosticSeverityError,
2118+
Summary: "Unknown Action Type",
2119+
Detail: fmt.Sprintf("The %q action type is not supported by this provider.", req.ActionType),
2120+
},
2121+
},
2122+
},
2123+
})
2124+
2125+
resp := &tfprotov5.InvokeActionServerStream{
2126+
Events: slices.Values(event),
2127+
}
2128+
2129+
return resp, nil
2130+
}
2131+
20682132
func pathToAttributePath(path cty.Path) *tftypes.AttributePath {
20692133
var steps []tftypes.AttributePathStep
20702134

helper/schema/grpc_provider_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3763,6 +3763,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
37633763
Functions: []tfprotov5.FunctionMetadata{},
37643764
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
37653765
ListResources: []tfprotov5.ListResourceMetadata{},
3766+
Actions: []tfprotov5.ActionMetadata{},
37663767
Resources: []tfprotov5.ResourceMetadata{},
37673768
ServerCapabilities: &tfprotov5.ServerCapabilities{
37683769
GetProviderSchemaOptional: true,
@@ -3792,6 +3793,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
37923793
Functions: []tfprotov5.FunctionMetadata{},
37933794
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
37943795
ListResources: []tfprotov5.ListResourceMetadata{},
3796+
Actions: []tfprotov5.ActionMetadata{},
37953797
Resources: []tfprotov5.ResourceMetadata{
37963798
{
37973799
TypeName: "test_resource1",
@@ -3817,6 +3819,7 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
38173819
Functions: []tfprotov5.FunctionMetadata{},
38183820
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
38193821
ListResources: []tfprotov5.ListResourceMetadata{},
3822+
Actions: []tfprotov5.ActionMetadata{},
38203823
Resources: []tfprotov5.ResourceMetadata{
38213824
{
38223825
TypeName: "test_resource1",

0 commit comments

Comments
 (0)