@@ -6,11 +6,75 @@ package proto6server
66import (
77 "context"
88
9+ "github.com/hashicorp/terraform-plugin-framework/diag"
10+ "github.com/hashicorp/terraform-plugin-framework/internal/fromproto6"
11+ "github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
12+ "github.com/hashicorp/terraform-plugin-framework/internal/logging"
13+ "github.com/hashicorp/terraform-plugin-framework/internal/toproto6"
914 "github.com/hashicorp/terraform-plugin-go/tfprotov6"
1015)
1116
17+ // invokeActionErrorDiagnostics returns a value suitable for
18+ // [InvokeActionServerStream.Events]. It yields a single result that contains
19+ // the given error diagnostics.
20+ func invokeActionErrorDiagnostics (ctx context.Context , diags diag.Diagnostics ) (* tfprotov6.InvokeActionServerStream , error ) {
21+ return & tfprotov6.InvokeActionServerStream {
22+ Events : func (push func (tfprotov6.InvokeActionEvent ) bool ) {
23+ push (tfprotov6.InvokeActionEvent {
24+ Type : tfprotov6.CompletedInvokeActionEventType {
25+ Diagnostics : toproto6 .Diagnostics (ctx , diags ),
26+ },
27+ })
28+ },
29+ }, nil
30+ }
31+
1232// InvokeAction satisfies the tfprotov6.ProviderServer interface.
1333func (s * Server ) InvokeAction (ctx context.Context , proto6Req * tfprotov6.InvokeActionRequest ) (* tfprotov6.InvokeActionServerStream , error ) {
14- // TODO:Actions: Implement
15- panic ("unimplemented" )
34+ ctx = s .registerContext (ctx )
35+ ctx = logging .InitContext (ctx )
36+
37+ fwResp := & fwserver.InvokeActionResponse {}
38+
39+ action , diags := s .FrameworkServer .Action (ctx , proto6Req .ActionType )
40+
41+ fwResp .Diagnostics .Append (diags ... )
42+
43+ if fwResp .Diagnostics .HasError () {
44+ return invokeActionErrorDiagnostics (ctx , fwResp .Diagnostics )
45+ }
46+
47+ actionSchema , diags := s .FrameworkServer .ActionSchema (ctx , proto6Req .ActionType )
48+
49+ fwResp .Diagnostics .Append (diags ... )
50+
51+ if fwResp .Diagnostics .HasError () {
52+ return invokeActionErrorDiagnostics (ctx , fwResp .Diagnostics )
53+ }
54+
55+ fwReq , diags := fromproto6 .InvokeActionRequest (ctx , proto6Req , action , actionSchema )
56+
57+ fwResp .Diagnostics .Append (diags ... )
58+
59+ if fwResp .Diagnostics .HasError () {
60+ return invokeActionErrorDiagnostics (ctx , fwResp .Diagnostics )
61+ }
62+
63+ s .FrameworkServer .InvokeAction (ctx , fwReq , fwResp )
64+
65+ // TODO:Actions: This is a stub implementation, so we aren't currently exposing any streaming mechanism to the developer.
66+ // That will eventually need to change to send progress events back to Terraform.
67+ //
68+ // This logic will likely need to be moved over to the "toproto" package as well.
69+ protoStream := & tfprotov6.InvokeActionServerStream {
70+ Events : func (push func (tfprotov6.InvokeActionEvent ) bool ) {
71+ push (tfprotov6.InvokeActionEvent {
72+ Type : tfprotov6.CompletedInvokeActionEventType {
73+ Diagnostics : toproto6 .Diagnostics (ctx , fwResp .Diagnostics ),
74+ },
75+ })
76+ },
77+ }
78+
79+ return protoStream , nil
1680}
0 commit comments