Skip to content

Commit 23a11cf

Browse files
authored
all: Initial ephemeral resource implementation (#1390)
* all: Initial ephemeral resource implementation * changelog
1 parent 24fa92a commit 23a11cf

File tree

3 files changed

+94
-9
lines changed

3 files changed

+94
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
kind: NOTES
2+
body: 'helper/schema: While this Go module will not receive support for ephemeral
3+
resource types, the provider server is updated to handle the new operations, which
4+
will be required to prevent errors when updating `terraform-plugin-framework` or
5+
`terraform-plugin-mux` in the future.'
6+
time: 2024-10-30T17:36:04.538418-04:00
7+
custom:
8+
Issue: "1390"

helper/schema/grpc_provider.go

+78-4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (s *GRPCProviderServer) GetMetadata(ctx context.Context, req *tfprotov5.Get
8484

8585
resp := &tfprotov5.GetMetadataResponse{
8686
DataSources: make([]tfprotov5.DataSourceMetadata, 0, len(s.provider.DataSourcesMap)),
87+
EphemeralResources: make([]tfprotov5.EphemeralResourceMetadata, 0),
8788
Functions: make([]tfprotov5.FunctionMetadata, 0),
8889
Resources: make([]tfprotov5.ResourceMetadata, 0, len(s.provider.ResourcesMap)),
8990
ServerCapabilities: s.serverCapabilities(),
@@ -110,10 +111,11 @@ func (s *GRPCProviderServer) GetProviderSchema(ctx context.Context, req *tfproto
110111
logging.HelperSchemaTrace(ctx, "Getting provider schema")
111112

112113
resp := &tfprotov5.GetProviderSchemaResponse{
113-
DataSourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.DataSourcesMap)),
114-
Functions: make(map[string]*tfprotov5.Function, 0),
115-
ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)),
116-
ServerCapabilities: s.serverCapabilities(),
114+
DataSourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.DataSourcesMap)),
115+
EphemeralResourceSchemas: make(map[string]*tfprotov5.Schema, 0),
116+
Functions: make(map[string]*tfprotov5.Function, 0),
117+
ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)),
118+
ServerCapabilities: s.serverCapabilities(),
117119
}
118120

119121
resp.Provider = &tfprotov5.Schema{
@@ -1482,6 +1484,78 @@ func (s *GRPCProviderServer) GetFunctions(ctx context.Context, req *tfprotov5.Ge
14821484
return resp, nil
14831485
}
14841486

1487+
func (s *GRPCProviderServer) ValidateEphemeralResourceConfig(ctx context.Context, req *tfprotov5.ValidateEphemeralResourceConfigRequest) (*tfprotov5.ValidateEphemeralResourceConfigResponse, error) {
1488+
ctx = logging.InitContext(ctx)
1489+
1490+
logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource validate")
1491+
1492+
resp := &tfprotov5.ValidateEphemeralResourceConfigResponse{
1493+
Diagnostics: []*tfprotov5.Diagnostic{
1494+
{
1495+
Severity: tfprotov5.DiagnosticSeverityError,
1496+
Summary: "Unknown Ephemeral Resource Type",
1497+
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
1498+
},
1499+
},
1500+
}
1501+
1502+
return resp, nil
1503+
}
1504+
1505+
func (s *GRPCProviderServer) OpenEphemeralResource(ctx context.Context, req *tfprotov5.OpenEphemeralResourceRequest) (*tfprotov5.OpenEphemeralResourceResponse, error) {
1506+
ctx = logging.InitContext(ctx)
1507+
1508+
logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource open")
1509+
1510+
resp := &tfprotov5.OpenEphemeralResourceResponse{
1511+
Diagnostics: []*tfprotov5.Diagnostic{
1512+
{
1513+
Severity: tfprotov5.DiagnosticSeverityError,
1514+
Summary: "Unknown Ephemeral Resource Type",
1515+
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
1516+
},
1517+
},
1518+
}
1519+
1520+
return resp, nil
1521+
}
1522+
1523+
func (s *GRPCProviderServer) RenewEphemeralResource(ctx context.Context, req *tfprotov5.RenewEphemeralResourceRequest) (*tfprotov5.RenewEphemeralResourceResponse, error) {
1524+
ctx = logging.InitContext(ctx)
1525+
1526+
logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource renew")
1527+
1528+
resp := &tfprotov5.RenewEphemeralResourceResponse{
1529+
Diagnostics: []*tfprotov5.Diagnostic{
1530+
{
1531+
Severity: tfprotov5.DiagnosticSeverityError,
1532+
Summary: "Unknown Ephemeral Resource Type",
1533+
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
1534+
},
1535+
},
1536+
}
1537+
1538+
return resp, nil
1539+
}
1540+
1541+
func (s *GRPCProviderServer) CloseEphemeralResource(ctx context.Context, req *tfprotov5.CloseEphemeralResourceRequest) (*tfprotov5.CloseEphemeralResourceResponse, error) {
1542+
ctx = logging.InitContext(ctx)
1543+
1544+
logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource close")
1545+
1546+
resp := &tfprotov5.CloseEphemeralResourceResponse{
1547+
Diagnostics: []*tfprotov5.Diagnostic{
1548+
{
1549+
Severity: tfprotov5.DiagnosticSeverityError,
1550+
Summary: "Unknown Ephemeral Resource Type",
1551+
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
1552+
},
1553+
},
1554+
}
1555+
1556+
return resp, nil
1557+
}
1558+
14851559
func pathToAttributePath(path cty.Path) *tftypes.AttributePath {
14861560
var steps []tftypes.AttributePathStep
14871561

helper/schema/grpc_provider_test.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -3319,8 +3319,9 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
33193319
TypeName: "test_datasource2",
33203320
},
33213321
},
3322-
Functions: []tfprotov5.FunctionMetadata{},
3323-
Resources: []tfprotov5.ResourceMetadata{},
3322+
Functions: []tfprotov5.FunctionMetadata{},
3323+
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
3324+
Resources: []tfprotov5.ResourceMetadata{},
33243325
ServerCapabilities: &tfprotov5.ServerCapabilities{
33253326
GetProviderSchemaOptional: true,
33263327
},
@@ -3346,7 +3347,8 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
33463347
TypeName: "test_datasource2",
33473348
},
33483349
},
3349-
Functions: []tfprotov5.FunctionMetadata{},
3350+
Functions: []tfprotov5.FunctionMetadata{},
3351+
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
33503352
Resources: []tfprotov5.ResourceMetadata{
33513353
{
33523354
TypeName: "test_resource1",
@@ -3368,8 +3370,9 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
33683370
},
33693371
},
33703372
Expected: &tfprotov5.GetMetadataResponse{
3371-
DataSources: []tfprotov5.DataSourceMetadata{},
3372-
Functions: []tfprotov5.FunctionMetadata{},
3373+
DataSources: []tfprotov5.DataSourceMetadata{},
3374+
Functions: []tfprotov5.FunctionMetadata{},
3375+
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
33733376
Resources: []tfprotov5.ResourceMetadata{
33743377
{
33753378
TypeName: "test_resource1",

0 commit comments

Comments
 (0)