Skip to content

Commit 7ff6ef6

Browse files
authored
tfprotov5+tfprotov6: Require EphemeralResourceServer in ProviderServer (#465)
* tfprotov5+tfprotov6: Require `EphemeralResourceServer` in `ProviderServer` * add changelogs
1 parent afd18f1 commit 7ff6ef6

File tree

7 files changed

+36
-240
lines changed

7 files changed

+36
-240
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: BREAKING CHANGES
2+
body: 'tfprotov5+tfprotov6: `EphemeralResourceServer` interface is now required in
3+
`ProviderServer`. Implementations not needing ephemeral resource support can return
4+
errors from the `*EphemeralResource` methods.'
5+
time: 2025-01-21T17:35:56.137392-05:00
6+
custom:
7+
Issue: "442"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: BREAKING CHANGES
2+
body: 'tfprotov5+tfprotov6: Removed temporary `ProviderServerWithEphemeralResources`
3+
interface type. Use `EphemeralResourceServer` instead.'
4+
time: 2025-01-21T17:45:09.953934-05:00
5+
custom:
6+
Issue: "442"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: NOTES
2+
body: 'all: To prevent compilation errors, ensure your Go module is updated to at least
3+
4+
and [email protected] before upgrading this dependency.'
5+
time: 2025-01-21T17:36:53.645571-05:00
6+
custom:
7+
Issue: "442"

tfprotov5/provider.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,12 @@ type ProviderServer interface {
5454
// terraform-plugin-go, so they are their own interface that is composed
5555
// into ProviderServer.
5656
FunctionServer
57-
}
58-
59-
// ProviderServerWithEphemeralResources is a temporary interface for servers
60-
// to implement Ephemeral Resource RPC handling with:
61-
//
62-
// - ValidateEphemeralResourceConfig
63-
// - OpenEphemeralResource
64-
// - RenewEphemeralResource
65-
// - CloseEphemeralResource
66-
//
67-
// Deprecated: The EphemeralResourceServer methods will be moved into the
68-
// ProviderServer interface and this interface will be removed in a future
69-
// version.
70-
type ProviderServerWithEphemeralResources interface {
71-
ProviderServer
7257

7358
// EphemeralResourceServer is an interface encapsulating all the ephemeral
74-
// resource-related RPC requests.
59+
// resource-related RPC requests. ProviderServer implementations must
60+
// implement them, but they are a handy interface for defining what an
61+
// ephemeral resource is to terraform-plugin-go, so they're their own
62+
// interface that is composed into ProviderServer.
7563
EphemeralResourceServer
7664
}
7765

tfprotov5/tf5server/server.go

+4-104
Original file line numberDiff line numberDiff line change
@@ -1013,38 +1013,13 @@ func (s *server) ValidateEphemeralResourceConfig(ctx context.Context, protoReq *
10131013
logging.ProtocolTrace(ctx, "Received request")
10141014
defer logging.ProtocolTrace(ctx, "Served request")
10151015

1016-
// TODO: Remove this check and error in preference of
1017-
// s.downstream.ValidateEphemeralResourceConfig below once ProviderServer interface
1018-
// implements the EphemeralResourceServer RPC methods.
1019-
// nolint:staticcheck
1020-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov5.ProviderServerWithEphemeralResources)
1021-
if !ok {
1022-
logging.ProtocolError(ctx, "ProviderServer does not implement ValidateEphemeralResourceConfig")
1023-
1024-
protoResp := &tfplugin5.ValidateEphemeralResourceConfig_Response{
1025-
Diagnostics: []*tfplugin5.Diagnostic{
1026-
{
1027-
Severity: tfplugin5.Diagnostic_ERROR,
1028-
Summary: "Provider Validate Ephemeral Resource Config Not Implemented",
1029-
Detail: "A ValidateEphemeralResourceConfig call was received by the provider, however the provider does not implement the call. " +
1030-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1031-
},
1032-
},
1033-
}
1034-
1035-
return protoResp, nil
1036-
}
1037-
10381016
req := fromproto.ValidateEphemeralResourceConfigRequest(protoReq)
10391017

10401018
logging.ProtocolData(ctx, s.protocolDataDir, rpc, "Request", "Config", req.Config)
10411019

10421020
ctx = tf5serverlogging.DownstreamRequest(ctx)
10431021

1044-
// TODO: Update this to call downstream once optional interface is removed
1045-
// resp, err := s.downstream.ValidateEphemeralResourceConfig(ctx, req)
1046-
resp, err := ephemeralResourceProviderServer.ValidateEphemeralResourceConfig(ctx, req)
1047-
1022+
resp, err := s.downstream.ValidateEphemeralResourceConfig(ctx, req)
10481023
if err != nil {
10491024
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
10501025
return nil, err
@@ -1066,38 +1041,13 @@ func (s *server) OpenEphemeralResource(ctx context.Context, protoReq *tfplugin5.
10661041
logging.ProtocolTrace(ctx, "Received request")
10671042
defer logging.ProtocolTrace(ctx, "Served request")
10681043

1069-
// TODO: Remove this check and error in preference of
1070-
// s.downstream.OpenEphemeralResource below once ProviderServer interface
1071-
// implements the EphemeralResourceServer RPC methods.
1072-
// nolint:staticcheck
1073-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov5.ProviderServerWithEphemeralResources)
1074-
if !ok {
1075-
logging.ProtocolError(ctx, "ProviderServer does not implement OpenEphemeralResource")
1076-
1077-
protoResp := &tfplugin5.OpenEphemeralResource_Response{
1078-
Diagnostics: []*tfplugin5.Diagnostic{
1079-
{
1080-
Severity: tfplugin5.Diagnostic_ERROR,
1081-
Summary: "Provider Open Ephemeral Resource Not Implemented",
1082-
Detail: "A OpenEphemeralResource call was received by the provider, however the provider does not implement the call. " +
1083-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1084-
},
1085-
},
1086-
}
1087-
1088-
return protoResp, nil
1089-
}
1090-
10911044
req := fromproto.OpenEphemeralResourceRequest(protoReq)
10921045

10931046
tf5serverlogging.OpenEphemeralResourceClientCapabilities(ctx, req.ClientCapabilities)
10941047
logging.ProtocolData(ctx, s.protocolDataDir, rpc, "Request", "Config", req.Config)
10951048
ctx = tf5serverlogging.DownstreamRequest(ctx)
10961049

1097-
// TODO: Update this to call downstream once optional interface is removed
1098-
// resp, err := s.downstream.OpenEphemeralResource(ctx, req)
1099-
resp, err := ephemeralResourceProviderServer.OpenEphemeralResource(ctx, req)
1100-
1050+
resp, err := s.downstream.OpenEphemeralResource(ctx, req)
11011051
if err != nil {
11021052
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
11031053
return nil, err
@@ -1125,36 +1075,11 @@ func (s *server) RenewEphemeralResource(ctx context.Context, protoReq *tfplugin5
11251075
logging.ProtocolTrace(ctx, "Received request")
11261076
defer logging.ProtocolTrace(ctx, "Served request")
11271077

1128-
// TODO: Remove this check and error in preference of
1129-
// s.downstream.RenewEphemeralResource below once ProviderServer interface
1130-
// implements the EphemeralResourceServer RPC methods.
1131-
// nolint:staticcheck
1132-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov5.ProviderServerWithEphemeralResources)
1133-
if !ok {
1134-
logging.ProtocolError(ctx, "ProviderServer does not implement RenewEphemeralResource")
1135-
1136-
protoResp := &tfplugin5.RenewEphemeralResource_Response{
1137-
Diagnostics: []*tfplugin5.Diagnostic{
1138-
{
1139-
Severity: tfplugin5.Diagnostic_ERROR,
1140-
Summary: "Provider Renew Ephemeral Resource Not Implemented",
1141-
Detail: "A RenewEphemeralResource call was received by the provider, however the provider does not implement the call. " +
1142-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1143-
},
1144-
},
1145-
}
1146-
1147-
return protoResp, nil
1148-
}
1149-
11501078
req := fromproto.RenewEphemeralResourceRequest(protoReq)
11511079

11521080
ctx = tf5serverlogging.DownstreamRequest(ctx)
11531081

1154-
// TODO: Update this to call downstream once optional interface is removed
1155-
// resp, err := s.downstream.RenewEphemeralResource(ctx, req)
1156-
resp, err := ephemeralResourceProviderServer.RenewEphemeralResource(ctx, req)
1157-
1082+
resp, err := s.downstream.RenewEphemeralResource(ctx, req)
11581083
if err != nil {
11591084
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
11601085
return nil, err
@@ -1176,36 +1101,11 @@ func (s *server) CloseEphemeralResource(ctx context.Context, protoReq *tfplugin5
11761101
logging.ProtocolTrace(ctx, "Received request")
11771102
defer logging.ProtocolTrace(ctx, "Served request")
11781103

1179-
// TODO: Remove this check and error in preference of
1180-
// s.downstream.CloseEphemeralResource below once ProviderServer interface
1181-
// implements the EphemeralResourceServer RPC methods.
1182-
// nolint:staticcheck
1183-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov5.ProviderServerWithEphemeralResources)
1184-
if !ok {
1185-
logging.ProtocolError(ctx, "ProviderServer does not implement CloseEphemeralResource")
1186-
1187-
protoResp := &tfplugin5.CloseEphemeralResource_Response{
1188-
Diagnostics: []*tfplugin5.Diagnostic{
1189-
{
1190-
Severity: tfplugin5.Diagnostic_ERROR,
1191-
Summary: "Provider Close Ephemeral Resource Not Implemented",
1192-
Detail: "A CloseEphemeralResource call was received by the provider, however the provider does not implement the call. " +
1193-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1194-
},
1195-
},
1196-
}
1197-
1198-
return protoResp, nil
1199-
}
1200-
12011104
req := fromproto.CloseEphemeralResourceRequest(protoReq)
12021105

12031106
ctx = tf5serverlogging.DownstreamRequest(ctx)
12041107

1205-
// TODO: Update this to call downstream once optional interface is removed
1206-
// resp, err := s.downstream.CloseEphemeralResource(ctx, req)
1207-
resp, err := ephemeralResourceProviderServer.CloseEphemeralResource(ctx, req)
1208-
1108+
resp, err := s.downstream.CloseEphemeralResource(ctx, req)
12091109
if err != nil {
12101110
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
12111111
return nil, err

tfprotov6/provider.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,12 @@ type ProviderServer interface {
5454
// terraform-plugin-go, so they are their own interface that is composed
5555
// into ProviderServer.
5656
FunctionServer
57-
}
58-
59-
// ProviderServerWithEphemeralResources is a temporary interface for servers
60-
// to implement Ephemeral Resource RPC handling with:
61-
//
62-
// - ValidateEphemeralResourceConfig
63-
// - OpenEphemeralResource
64-
// - RenewEphemeralResource
65-
// - CloseEphemeralResource
66-
//
67-
// Deprecated: The EphemeralResourceServer methods will be moved into the
68-
// ProviderServer interface and this interface will be removed in a future
69-
// version.
70-
type ProviderServerWithEphemeralResources interface {
71-
ProviderServer
7257

7358
// EphemeralResourceServer is an interface encapsulating all the ephemeral
74-
// resource-related RPC requests.
59+
// resource-related RPC requests. ProviderServer implementations must
60+
// implement them, but they are a handy interface for defining what an
61+
// ephemeral resource is to terraform-plugin-go, so they're their own
62+
// interface that is composed into ProviderServer.
7563
EphemeralResourceServer
7664
}
7765

tfprotov6/tf6server/server.go

+4-104
Original file line numberDiff line numberDiff line change
@@ -1013,38 +1013,13 @@ func (s *server) ValidateEphemeralResourceConfig(ctx context.Context, protoReq *
10131013
logging.ProtocolTrace(ctx, "Received request")
10141014
defer logging.ProtocolTrace(ctx, "Served request")
10151015

1016-
// TODO: Remove this check and error in preference of
1017-
// s.downstream.ValidateEphemeralResourceConfig below once ProviderServer interface
1018-
// implements the EphemeralResourceServer RPC methods.
1019-
// nolint:staticcheck
1020-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov6.ProviderServerWithEphemeralResources)
1021-
if !ok {
1022-
logging.ProtocolError(ctx, "ProviderServer does not implement ValidateEphemeralResourceConfig")
1023-
1024-
protoResp := &tfplugin6.ValidateEphemeralResourceConfig_Response{
1025-
Diagnostics: []*tfplugin6.Diagnostic{
1026-
{
1027-
Severity: tfplugin6.Diagnostic_ERROR,
1028-
Summary: "Provider Validate Ephemeral Resource Config Not Implemented",
1029-
Detail: "A ValidateEphemeralResourceConfig call was received by the provider, however the provider does not implement the call. " +
1030-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1031-
},
1032-
},
1033-
}
1034-
1035-
return protoResp, nil
1036-
}
1037-
10381016
req := fromproto.ValidateEphemeralResourceConfigRequest(protoReq)
10391017

10401018
logging.ProtocolData(ctx, s.protocolDataDir, rpc, "Request", "Config", req.Config)
10411019

10421020
ctx = tf6serverlogging.DownstreamRequest(ctx)
10431021

1044-
// TODO: Update this to call downstream once optional interface is removed
1045-
// resp, err := s.downstream.ValidateEphemeralResourceConfig(ctx, req)
1046-
resp, err := ephemeralResourceProviderServer.ValidateEphemeralResourceConfig(ctx, req)
1047-
1022+
resp, err := s.downstream.ValidateEphemeralResourceConfig(ctx, req)
10481023
if err != nil {
10491024
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
10501025
return nil, err
@@ -1066,39 +1041,14 @@ func (s *server) OpenEphemeralResource(ctx context.Context, protoReq *tfplugin6.
10661041
logging.ProtocolTrace(ctx, "Received request")
10671042
defer logging.ProtocolTrace(ctx, "Served request")
10681043

1069-
// TODO: Remove this check and error in preference of
1070-
// s.downstream.OpenEphemeralResource below once ProviderServer interface
1071-
// implements the EphemeralResourceServer RPC methods.
1072-
// nolint:staticcheck
1073-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov6.ProviderServerWithEphemeralResources)
1074-
if !ok {
1075-
logging.ProtocolError(ctx, "ProviderServer does not implement OpenEphemeralResource")
1076-
1077-
protoResp := &tfplugin6.OpenEphemeralResource_Response{
1078-
Diagnostics: []*tfplugin6.Diagnostic{
1079-
{
1080-
Severity: tfplugin6.Diagnostic_ERROR,
1081-
Summary: "Provider Open Ephemeral Resource Not Implemented",
1082-
Detail: "A OpenEphemeralResource call was received by the provider, however the provider does not implement the call. " +
1083-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1084-
},
1085-
},
1086-
}
1087-
1088-
return protoResp, nil
1089-
}
1090-
10911044
req := fromproto.OpenEphemeralResourceRequest(protoReq)
10921045

10931046
tf6serverlogging.OpenEphemeralResourceClientCapabilities(ctx, req.ClientCapabilities)
10941047
logging.ProtocolData(ctx, s.protocolDataDir, rpc, "Request", "Config", req.Config)
10951048

10961049
ctx = tf6serverlogging.DownstreamRequest(ctx)
10971050

1098-
// TODO: Update this to call downstream once optional interface is removed
1099-
// resp, err := s.downstream.OpenEphemeralResource(ctx, req)
1100-
resp, err := ephemeralResourceProviderServer.OpenEphemeralResource(ctx, req)
1101-
1051+
resp, err := s.downstream.OpenEphemeralResource(ctx, req)
11021052
if err != nil {
11031053
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
11041054
return nil, err
@@ -1126,36 +1076,11 @@ func (s *server) RenewEphemeralResource(ctx context.Context, protoReq *tfplugin6
11261076
logging.ProtocolTrace(ctx, "Received request")
11271077
defer logging.ProtocolTrace(ctx, "Served request")
11281078

1129-
// TODO: Remove this check and error in preference of
1130-
// s.downstream.RenewEphemeralResource below once ProviderServer interface
1131-
// implements the EphemeralResourceServer RPC methods.
1132-
// nolint:staticcheck
1133-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov6.ProviderServerWithEphemeralResources)
1134-
if !ok {
1135-
logging.ProtocolError(ctx, "ProviderServer does not implement RenewEphemeralResource")
1136-
1137-
protoResp := &tfplugin6.RenewEphemeralResource_Response{
1138-
Diagnostics: []*tfplugin6.Diagnostic{
1139-
{
1140-
Severity: tfplugin6.Diagnostic_ERROR,
1141-
Summary: "Provider Renew Ephemeral Resource Not Implemented",
1142-
Detail: "A RenewEphemeralResource call was received by the provider, however the provider does not implement the call. " +
1143-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1144-
},
1145-
},
1146-
}
1147-
1148-
return protoResp, nil
1149-
}
1150-
11511079
req := fromproto.RenewEphemeralResourceRequest(protoReq)
11521080

11531081
ctx = tf6serverlogging.DownstreamRequest(ctx)
11541082

1155-
// TODO: Update this to call downstream once optional interface is removed
1156-
// resp, err := s.downstream.RenewEphemeralResource(ctx, req)
1157-
resp, err := ephemeralResourceProviderServer.RenewEphemeralResource(ctx, req)
1158-
1083+
resp, err := s.downstream.RenewEphemeralResource(ctx, req)
11591084
if err != nil {
11601085
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
11611086
return nil, err
@@ -1177,36 +1102,11 @@ func (s *server) CloseEphemeralResource(ctx context.Context, protoReq *tfplugin6
11771102
logging.ProtocolTrace(ctx, "Received request")
11781103
defer logging.ProtocolTrace(ctx, "Served request")
11791104

1180-
// TODO: Remove this check and error in preference of
1181-
// s.downstream.CloseEphemeralResource below once ProviderServer interface
1182-
// implements the EphemeralResourceServer RPC methods.
1183-
// nolint:staticcheck
1184-
ephemeralResourceProviderServer, ok := s.downstream.(tfprotov6.ProviderServerWithEphemeralResources)
1185-
if !ok {
1186-
logging.ProtocolError(ctx, "ProviderServer does not implement CloseEphemeralResource")
1187-
1188-
protoResp := &tfplugin6.CloseEphemeralResource_Response{
1189-
Diagnostics: []*tfplugin6.Diagnostic{
1190-
{
1191-
Severity: tfplugin6.Diagnostic_ERROR,
1192-
Summary: "Provider Close Ephemeral Resource Not Implemented",
1193-
Detail: "A CloseEphemeralResource call was received by the provider, however the provider does not implement the call. " +
1194-
"Either upgrade the provider to a version that implements ephemeral resource support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1195-
},
1196-
},
1197-
}
1198-
1199-
return protoResp, nil
1200-
}
1201-
12021105
req := fromproto.CloseEphemeralResourceRequest(protoReq)
12031106

12041107
ctx = tf6serverlogging.DownstreamRequest(ctx)
12051108

1206-
// TODO: Update this to call downstream once optional interface is removed
1207-
// resp, err := s.downstream.CloseEphemeralResource(ctx, req)
1208-
resp, err := ephemeralResourceProviderServer.CloseEphemeralResource(ctx, req)
1209-
1109+
resp, err := s.downstream.CloseEphemeralResource(ctx, req)
12101110
if err != nil {
12111111
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
12121112
return nil, err

0 commit comments

Comments
 (0)