Skip to content

Commit f185ebe

Browse files
committed
Implement ReadStateBytes + WriteStateBytes
1 parent 1a097f4 commit f185ebe

File tree

16 files changed

+1354
-515
lines changed

16 files changed

+1354
-515
lines changed

docs/plugin-protocol/tfplugin6.proto

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ service Provider {
425425
// ConfigureStateStore configures the state store, such as S3 connection in the context of already configured provider
426426
rpc ConfigureStateStore(ConfigureStateStore.Request) returns (ConfigureStateStore.Response);
427427

428+
// ReadStateBytes streams byte chunks of a given state file from a state store
429+
rpc ReadStateBytes(ReadStateBytes.Request) returns (stream ReadStateBytes.ResponseChunk);
430+
// WriteStateBytes streams byte chunks of a given state file into a state store
431+
rpc WriteStateBytes(stream WriteStateBytes.RequestChunk) returns (stream WriteStateBytes.Response);
432+
428433
// GetStates returns a list of all states (i.e. CE workspaces) managed by a given state store
429434
rpc GetStates(GetStates.Request) returns (GetStates.Response);
430435
// DeleteState instructs a given state store to delete a specific state (i.e. a CE workspace)
@@ -939,6 +944,37 @@ message ConfigureStateStore {
939944
}
940945
}
941946

947+
message ReadStateBytes {
948+
message Request {
949+
string type_name = 1;
950+
string state_id = 2;
951+
}
952+
message ResponseChunk {
953+
bytes data = 1;
954+
// supplied with the first chunk
955+
optional StateMeta meta = 2;
956+
repeated Diagnostic diagnostics = 3;
957+
}
958+
}
959+
960+
message WriteStateBytes {
961+
message RequestChunk {
962+
string type_name = 1;
963+
bytes data = 2;
964+
string state_id = 3;
965+
// supplied with the first chunk
966+
optional StateMeta meta = 4;
967+
}
968+
message Response {
969+
repeated Diagnostic diagnostics = 1;
970+
}
971+
}
972+
973+
message StateMeta {
974+
bytes checksum = 1;
975+
int64 number_of_chunks = 2;
976+
}
977+
942978
message GetStates {
943979
message Request {
944980
string type_name = 1;

internal/builtin/providers/terraform/provider.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ func (p *Provider) ConfigureStateStore(req providers.ConfigureStateStoreRequest)
291291
return resp
292292
}
293293

294+
func (p *Provider) ReadStateBytes(req providers.ReadStateBytesRequest) providers.ReadStateBytesResponseChunk {
295+
var resp providers.ReadStateBytesResponseChunk
296+
resp.Diagnostics.Append(fmt.Errorf("unsupported state store type %q", req.TypeName))
297+
return resp
298+
}
299+
300+
func (p *Provider) WriteStateBytes(req providers.WriteStateBytesRequestChunk) providers.WriteStateBytesResponse {
301+
var resp providers.WriteStateBytesResponse
302+
resp.Diagnostics.Append(fmt.Errorf("unsupported state store type %q", req.TypeName))
303+
return resp
304+
}
305+
294306
func (p *Provider) GetStates(req providers.GetStatesRequest) providers.GetStatesResponse {
295307
var resp providers.GetStatesResponse
296308
resp.Diagnostics.Append(fmt.Errorf("unsupported state store type %q", req.TypeName))

internal/grpcwrap/provider6.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,14 @@ func (p *provider6) ConfigureStateStore(ctx context.Context, req *tfplugin6.Conf
918918
panic("not implemented")
919919
}
920920

921+
func (p *provider6) ReadStateBytes(req *tfplugin6.ReadStateBytes_Request, srv tfplugin6.Provider_ReadStateBytesServer) error {
922+
panic("not implemented")
923+
}
924+
925+
func (p *provider6) WriteStateBytes(srv tfplugin6.Provider_WriteStateBytesServer) error {
926+
panic("not implemented")
927+
}
928+
921929
func (p *provider6) GetStates(ctx context.Context, req *tfplugin6.GetStates_Request) (*tfplugin6.GetStates_Response, error) {
922930
panic("not implemented")
923931
}

internal/plugin/grpc_provider.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,14 @@ func (p *GRPCProvider) ConfigureStateStore(r providers.ConfigureStateStoreReques
14181418
panic("not implemented")
14191419
}
14201420

1421+
func (p *GRPCProvider) ReadStateBytes(r providers.ReadStateBytesRequest) providers.ReadStateBytesResponseChunk {
1422+
panic("not implemented")
1423+
}
1424+
1425+
func (p *GRPCProvider) WriteStateBytes(r providers.WriteStateBytesRequestChunk) providers.WriteStateBytesResponse {
1426+
panic("not implemented")
1427+
}
1428+
14211429
func (p *GRPCProvider) GetStates(r providers.GetStatesRequest) providers.GetStatesResponse {
14221430
panic("not implemented")
14231431
}

internal/plugin6/grpc_provider.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,22 @@ func (p *GRPCProvider) ConfigureStateStore(r providers.ConfigureStateStoreReques
14781478
return resp
14791479
}
14801480

1481+
func (p *GRPCProvider) ReadStateBytes(r providers.ReadStateBytesRequest) (resp providers.ReadStateBytesResponseChunk) {
1482+
logger.Trace("GRPCProvider.v6: ReadStateBytes")
1483+
1484+
// TODO
1485+
1486+
return resp
1487+
}
1488+
1489+
func (p *GRPCProvider) WriteStateBytes(r providers.WriteStateBytesRequestChunk) providers.WriteStateBytesResponse {
1490+
logger.Trace("GRPCProvider.v6: WriteStateBytes")
1491+
1492+
// TODO
1493+
1494+
return providers.WriteStateBytesResponse{}
1495+
}
1496+
14811497
func (p *GRPCProvider) GetStates(r providers.GetStatesRequest) (resp providers.GetStatesResponse) {
14821498
logger.Trace("GRPCProvider.v6: GetStates")
14831499

internal/plugin6/mock_proto/mock.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/provider-simple-v6/provider.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ func (s simple) ConfigureStateStore(req providers.ConfigureStateStoreRequest) pr
311311
panic("not implemented")
312312
}
313313

314+
func (s simple) ReadStateBytes(req providers.ReadStateBytesRequest) providers.ReadStateBytesResponseChunk {
315+
panic("not implemented")
316+
}
317+
318+
func (s simple) WriteStateBytes(req providers.WriteStateBytesRequestChunk) providers.WriteStateBytesResponse {
319+
panic("not implemented")
320+
}
321+
314322
func (s simple) GetStates(req providers.GetStatesRequest) providers.GetStatesResponse {
315323
panic("not implemented")
316324
}

internal/provider-simple/provider.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ func (s simple) ConfigureStateStore(req providers.ConfigureStateStoreRequest) pr
271271
panic("not implemented")
272272
}
273273

274+
func (s simple) ReadStateBytes(req providers.ReadStateBytesRequest) providers.ReadStateBytesResponseChunk {
275+
panic("not implemented")
276+
}
277+
278+
func (s simple) WriteStateBytes(req providers.WriteStateBytesRequestChunk) providers.WriteStateBytesResponse {
279+
panic("not implemented")
280+
}
281+
274282
func (s simple) GetStates(req providers.GetStatesRequest) providers.GetStatesResponse {
275283
// provider-simple uses protocol version 5, which does not include the RPC that maps to this method
276284
panic("not implemented")

internal/providers/mock.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,14 @@ func (m *Mock) ConfigureStateStore(req ConfigureStateStoreRequest) ConfigureStat
432432
return m.Provider.ConfigureStateStore(req)
433433
}
434434

435+
func (m *Mock) ReadStateBytes(req ReadStateBytesRequest) ReadStateBytesResponseChunk {
436+
return m.Provider.ReadStateBytes(req)
437+
}
438+
439+
func (m *Mock) WriteStateBytes(req WriteStateBytesRequestChunk) WriteStateBytesResponse {
440+
return m.Provider.WriteStateBytes(req)
441+
}
442+
435443
func (m *Mock) GetStates(req GetStatesRequest) GetStatesResponse {
436444
return m.Provider.GetStates(req)
437445
}

internal/providers/provider.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ type Interface interface {
118118
// ConfigureStateStore configures the state store, such as S3 connection in the context of already configured provider
119119
ConfigureStateStore(ConfigureStateStoreRequest) ConfigureStateStoreResponse
120120

121+
// ReadStateBytes streams byte chunks of a given state file from a state store
122+
ReadStateBytes(ReadStateBytesRequest) ReadStateBytesResponseChunk
123+
// WriteStateBytes streams byte chunks of a given state file into a state store
124+
WriteStateBytes(WriteStateBytesRequestChunk) WriteStateBytesResponse
125+
121126
// GetStates returns a list of all states (i.e. CE workspaces) managed by a given state store
122127
GetStates(GetStatesRequest) GetStatesResponse
123128
// DeleteState instructs a given state store to delete a specific state (i.e. a CE workspace)
@@ -850,6 +855,43 @@ type ConfigureStateStoreResponse struct {
850855
Diagnostics tfdiags.Diagnostics
851856
}
852857

858+
type ReadStateBytesRequest struct {
859+
// TypeName is the name of the state store to read state from
860+
TypeName string
861+
// StateId is the ID of a state file to read
862+
StateId string
863+
}
864+
865+
type ReadStateBytesResponseChunk struct {
866+
// Data is a chunk of bytes of the given state file being read
867+
Data []byte
868+
// Meta is metadata concerning the state file stream
869+
Meta *StateMeta
870+
// Diagnostics contains any warnings or errors from the method call.
871+
Diagnostics tfdiags.Diagnostics
872+
}
873+
874+
type WriteStateBytesRequestChunk struct {
875+
// TypeName is the name of the state store to write state to
876+
TypeName string
877+
// Data is a chunk of bytes of the given state file being written
878+
Data []byte
879+
// StateId is the ID of a state file to write
880+
StateId string
881+
// Meta is metadata concerning the state file stream
882+
Meta *StateMeta
883+
}
884+
885+
type WriteStateBytesResponse struct {
886+
// Diagnostics contains any warnings or errors from the method call.
887+
Diagnostics tfdiags.Diagnostics
888+
}
889+
890+
type StateMeta struct {
891+
Checksum []byte
892+
NumberOfChunks int64
893+
}
894+
853895
type GetStatesRequest struct {
854896
// TypeName is the name of the state store to request the list of states from
855897
TypeName string

0 commit comments

Comments
 (0)