Skip to content

Add protobuf definitions for PSS #37177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions docs/plugin-protocol/tfplugin6.proto
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ service Provider {
// ConfigureStateStore configures the state store, such as S3 connection in the context of already configured provider
rpc ConfigureStateStore(ConfigureStateStore.Request) returns (ConfigureStateStore.Response);

rpc ReadState(ReadState.Request) returns (stream ReadState.ResponseChunk);
rpc WriteState(stream WriteState.RequestChunk) returns (stream WriteState.Response);

rpc LockState(LockState.Request) returns (LockState.Response);
rpc UnlockState(UnlockState.Request) returns (UnlockState.Response);
rpc GetStates(GetStates.Request) returns (GetStates.Response);
rpc DeleteState(DeleteState.Request) returns (DeleteState.Response);

//////// Graceful Shutdown
rpc StopProvider(StopProvider.Request) returns (StopProvider.Response);
}
Expand Down Expand Up @@ -875,3 +883,74 @@ message ConfigureStateStore {
repeated Diagnostic diagnostics = 1;
}
}

message ReadState {
message Request {
string type_name = 1;
string state_id = 2;
}
message ResponseChunk {
bytes data = 1;
// supplied with the first chunk
optional StateMeta meta = 2;
}
}

message WriteState {
message RequestChunk {
bytes data = 1;
string state_id = 2;
// supplied with the first chunk
optional StateMeta meta = 3;
}
message Response {
repeated Diagnostic diagnostics = 1;
}
}

message StateMeta {
bytes checksum = 1;
int64 number_of_chunks = 2;
}

message LockState {
message Request {
string type_name = 1;
string state_id = 2;
string operation = 3;
}
message Response {
string id = 1;
repeated Diagnostic diagnostics = 2;
}
}

message UnlockState {
message Request {
string type_name = 1;
string state_id = 2;
string lock_id = 3;
}
message Response {
repeated Diagnostic diagnostics = 1;
}
}

message GetStates {
message Request {
string type_name = 1;
}
message Response {
repeated string state_id = 1;
}
}

message DeleteState {
message Request {
string type_name = 1;
string state_id = 2;
}
message Response {
repeated Diagnostic diagnostics = 1;
}
}
6 changes: 6 additions & 0 deletions internal/builtin/providers/terraform/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,9 @@ func (p *Provider) ConfigureStateStore(req providers.ConfigureStateStoreRequest)
func (p *Provider) Close() error {
return nil
}

func (p *Provider) ValidateStorageConfig(req providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
var resp providers.ValidateStorageConfigResponse
resp.Diagnostics.Append(fmt.Errorf("unsupported storage type %q", req.TypeName))
return resp
}
1 change: 1 addition & 0 deletions internal/command/testing/test_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ var (
ReturnType: cty.Bool,
},
},
// TODO - add a State Stores map here?
}
)

Expand Down
7 changes: 7 additions & 0 deletions internal/grpcwrap/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
DataSourceSchemas: make(map[string]*tfplugin5.Schema),
EphemeralResourceSchemas: make(map[string]*tfplugin5.Schema),
ListResourceSchemas: make(map[string]*tfplugin5.Schema),
StateStoreSchemas: make(map[string]*tfplugin5.Schema),

Check failure on line 49 in internal/grpcwrap/provider.go

View workflow job for this annotation

GitHub Actions / End-to-end Tests

unknown field StateStoreSchemas in struct literal of type tfplugin5.GetProviderSchema_Response

Check failure on line 49 in internal/grpcwrap/provider.go

View workflow job for this annotation

GitHub Actions / Unit Tests

unknown field StateStoreSchemas in struct literal of type tfplugin5.GetProviderSchema_Response

Check failure on line 49 in internal/grpcwrap/provider.go

View workflow job for this annotation

GitHub Actions / Code Consistency Checks

unknown field StateStoreSchemas in struct literal of type tfplugin5.GetProviderSchema_Response
}

resp.Provider = &tfplugin5.Schema{
Expand Down Expand Up @@ -86,6 +87,12 @@
Block: convert.ConfigSchemaToProto(dat.Body),
}
}
for typ, dat := range p.schema.StateStores {
resp.StateStoreSchemas[typ] = &tfplugin5.Schema{

Check failure on line 91 in internal/grpcwrap/provider.go

View workflow job for this annotation

GitHub Actions / End-to-end Tests

resp.StateStoreSchemas undefined (type *tfplugin5.GetProviderSchema_Response has no field or method StateStoreSchemas)

Check failure on line 91 in internal/grpcwrap/provider.go

View workflow job for this annotation

GitHub Actions / Unit Tests

resp.StateStoreSchemas undefined (type *tfplugin5.GetProviderSchema_Response has no field or method StateStoreSchemas)

Check failure on line 91 in internal/grpcwrap/provider.go

View workflow job for this annotation

GitHub Actions / Code Consistency Checks

resp.StateStoreSchemas undefined (type *tfplugin5.GetProviderSchema_Response has no field or method StateStoreSchemas)
Version: int64(dat.Version),
Block: convert.ConfigSchemaToProto(dat.Body),
}
}
if decls, err := convert.FunctionDeclsToProto(p.schema.Functions); err == nil {
resp.Functions = decls
} else {
Expand Down
24 changes: 24 additions & 0 deletions internal/grpcwrap/provider6.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,30 @@ func (p *provider6) ConfigureStateStore(ctx context.Context, req *tfplugin6.Conf
panic("not implemented")
}

func (p *provider6) ReadState(req *tfplugin6.ReadState_Request, srv tfplugin6.Provider_ReadStateServer) error {
panic("not implemented")
}

func (p *provider6) WriteState(srv tfplugin6.Provider_WriteStateServer) error {
panic("not implemented")
}

func (p *provider6) LockState(ctx context.Context, req *tfplugin6.LockState_Request) (*tfplugin6.LockState_Response, error) {
panic("not implemented")
}

func (p *provider6) UnlockState(ctx context.Context, req *tfplugin6.UnlockState_Request) (*tfplugin6.UnlockState_Response, error) {
panic("not implemented")
}

func (p *provider6) GetStates(ctx context.Context, req *tfplugin6.GetStates_Request) (*tfplugin6.GetStates_Response, error) {
panic("not implemented")
}

func (p *provider6) DeleteState(ctx context.Context, req *tfplugin6.DeleteState_Request) (*tfplugin6.DeleteState_Response, error) {
panic("not implemented")
}

func (p *provider6) StopProvider(context.Context, *tfplugin6.StopProvider_Request) (*tfplugin6.StopProvider_Response, error) {
resp := &tfplugin6.StopProvider_Response{}
err := p.provider.Stop()
Expand Down
8 changes: 8 additions & 0 deletions internal/plugin/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (p *GRPCProviderPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Serve
return nil
}

var _ providers.Interface = &GRPCProvider{}

// GRPCProvider handles the client, or core side of the plugin rpc connection.
// The GRPCProvider methods are mostly a translation layer between the
// terraform providers types and the grpc proto types, directly converting
Expand Down Expand Up @@ -103,6 +105,7 @@ func (p *GRPCProvider) GetProviderSchema() providers.GetProviderSchemaResponse {
resp.DataSources = make(map[string]providers.Schema)
resp.EphemeralResourceTypes = make(map[string]providers.Schema)
resp.ListResourceTypes = make(map[string]providers.Schema)
// TODO: resp.StateStores = make(map[string]providers.Schema)

// Some providers may generate quite large schemas, and the internal default
// grpc response size limit is 4MB. 64MB should cover most any use case, and
Expand Down Expand Up @@ -1407,3 +1410,8 @@ func clientCapabilitiesToProto(c providers.ClientCapabilities) *proto.ClientCapa
WriteOnlyAttributesAllowed: c.WriteOnlyAttributesAllowed,
}
}

func (p *GRPCProvider) ValidateStorageConfig(r providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
// TODO
return providers.ValidateStorageConfigResponse{}
}
7 changes: 7 additions & 0 deletions internal/plugin6/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (p *GRPCProviderPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Serve
return nil
}

var _ providers.Interface = &GRPCProvider{}

// GRPCProvider handles the client, or core side of the plugin rpc connection.
// The GRPCProvider methods are mostly a translation layer between the
// terraform providers types and the grpc proto types, directly converting
Expand Down Expand Up @@ -1353,6 +1355,11 @@ func (p *GRPCProvider) ConfigureStateStore(r providers.ConfigureStateStoreReques
panic("not implemented")
}

func (p *GRPCProvider) ValidateStorageConfig(r providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
// TODO
return providers.ValidateStorageConfigResponse{}
}

// closing the grpc connection is final, and terraform will call it at the end of every phase.
func (p *GRPCProvider) Close() error {
logger.Trace("GRPCProvider.v6: Close")
Expand Down
120 changes: 120 additions & 0 deletions internal/plugin6/mock_proto/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/provider-simple-v6/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type simple struct {
schema providers.GetProviderSchemaResponse
}

var _ providers.Interface = simple{}

func Provider() providers.Interface {
simpleResource := providers.Schema{
Body: &configschema.Block{
Expand Down
3 changes: 3 additions & 0 deletions internal/provider-simple/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func Provider() providers.Interface {
EphemeralResourceTypes: map[string]providers.Schema{
"simple_resource": simpleResource,
},
StateStores: map[string]providers.Schema{
"simple_store": simpleResource,
},
ServerCapabilities: providers.ServerCapabilities{
PlanDestroy: true,
},
Expand Down
Loading
Loading