Skip to content

Commit

Permalink
all: Initial ephemeral resource implementation (#1390)
Browse files Browse the repository at this point in the history
* all: Initial ephemeral resource implementation

* changelog
  • Loading branch information
austinvalle authored Oct 31, 2024
1 parent 24fa92a commit 23a11cf
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .changes/unreleased/NOTES-20241030-173604.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: NOTES
body: 'helper/schema: While this Go module will not receive support for ephemeral
resource types, the provider server is updated to handle the new operations, which
will be required to prevent errors when updating `terraform-plugin-framework` or
`terraform-plugin-mux` in the future.'
time: 2024-10-30T17:36:04.538418-04:00
custom:
Issue: "1390"
82 changes: 78 additions & 4 deletions helper/schema/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (s *GRPCProviderServer) GetMetadata(ctx context.Context, req *tfprotov5.Get

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

resp := &tfprotov5.GetProviderSchemaResponse{
DataSourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.DataSourcesMap)),
Functions: make(map[string]*tfprotov5.Function, 0),
ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)),
ServerCapabilities: s.serverCapabilities(),
DataSourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.DataSourcesMap)),
EphemeralResourceSchemas: make(map[string]*tfprotov5.Schema, 0),
Functions: make(map[string]*tfprotov5.Function, 0),
ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)),
ServerCapabilities: s.serverCapabilities(),
}

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

func (s *GRPCProviderServer) ValidateEphemeralResourceConfig(ctx context.Context, req *tfprotov5.ValidateEphemeralResourceConfigRequest) (*tfprotov5.ValidateEphemeralResourceConfigResponse, error) {
ctx = logging.InitContext(ctx)

logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource validate")

resp := &tfprotov5.ValidateEphemeralResourceConfigResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Unknown Ephemeral Resource Type",
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
},
},
}

return resp, nil
}

func (s *GRPCProviderServer) OpenEphemeralResource(ctx context.Context, req *tfprotov5.OpenEphemeralResourceRequest) (*tfprotov5.OpenEphemeralResourceResponse, error) {
ctx = logging.InitContext(ctx)

logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource open")

resp := &tfprotov5.OpenEphemeralResourceResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Unknown Ephemeral Resource Type",
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
},
},
}

return resp, nil
}

func (s *GRPCProviderServer) RenewEphemeralResource(ctx context.Context, req *tfprotov5.RenewEphemeralResourceRequest) (*tfprotov5.RenewEphemeralResourceResponse, error) {
ctx = logging.InitContext(ctx)

logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource renew")

resp := &tfprotov5.RenewEphemeralResourceResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Unknown Ephemeral Resource Type",
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
},
},
}

return resp, nil
}

func (s *GRPCProviderServer) CloseEphemeralResource(ctx context.Context, req *tfprotov5.CloseEphemeralResourceRequest) (*tfprotov5.CloseEphemeralResourceResponse, error) {
ctx = logging.InitContext(ctx)

logging.HelperSchemaTrace(ctx, "Returning error for ephemeral resource close")

resp := &tfprotov5.CloseEphemeralResourceResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Unknown Ephemeral Resource Type",
Detail: fmt.Sprintf("The %q ephemeral resource type is not supported by this provider.", req.TypeName),
},
},
}

return resp, nil
}

func pathToAttributePath(path cty.Path) *tftypes.AttributePath {
var steps []tftypes.AttributePathStep

Expand Down
13 changes: 8 additions & 5 deletions helper/schema/grpc_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3319,8 +3319,9 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
TypeName: "test_datasource2",
},
},
Functions: []tfprotov5.FunctionMetadata{},
Resources: []tfprotov5.ResourceMetadata{},
Functions: []tfprotov5.FunctionMetadata{},
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
Resources: []tfprotov5.ResourceMetadata{},
ServerCapabilities: &tfprotov5.ServerCapabilities{
GetProviderSchemaOptional: true,
},
Expand All @@ -3346,7 +3347,8 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
TypeName: "test_datasource2",
},
},
Functions: []tfprotov5.FunctionMetadata{},
Functions: []tfprotov5.FunctionMetadata{},
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
Resources: []tfprotov5.ResourceMetadata{
{
TypeName: "test_resource1",
Expand All @@ -3368,8 +3370,9 @@ func TestGRPCProviderServerGetMetadata(t *testing.T) {
},
},
Expected: &tfprotov5.GetMetadataResponse{
DataSources: []tfprotov5.DataSourceMetadata{},
Functions: []tfprotov5.FunctionMetadata{},
DataSources: []tfprotov5.DataSourceMetadata{},
Functions: []tfprotov5.FunctionMetadata{},
EphemeralResources: []tfprotov5.EphemeralResourceMetadata{},
Resources: []tfprotov5.ResourceMetadata{
{
TypeName: "test_resource1",
Expand Down

0 comments on commit 23a11cf

Please sign in to comment.