Skip to content

Commit 3942f69

Browse files
radeksimkoSarahFrench
authored andcommitted
add protobuf definitions
1 parent 2c72198 commit 3942f69

File tree

18 files changed

+4942
-2781
lines changed

18 files changed

+4942
-2781
lines changed

docs/plugin-protocol/tfplugin6.proto

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,19 @@ service Provider {
375375
//////// Provider-contributed Functions
376376
rpc CallFunction(CallFunction.Request) returns (CallFunction.Response);
377377

378+
// ValidateStorageConfig fills in any default values and performs configuration validation
379+
rpc ValidateStorageConfig(ValidateStorage.Request) returns (ValidateStorage.Response);
380+
// ConfigureStorage configures the storage, such as S3 connection in the context of already configured provider
381+
rpc ConfigureStorage(ConfigureStorage.Request) returns (ConfigureStorage.Response);
382+
383+
rpc ReadState(ReadState.Request) returns (stream ReadState.ResponseChunk);
384+
rpc WriteState(stream WriteState.RequestChunk) returns (stream WriteState.Response);
385+
386+
rpc LockState(LockState.Request) returns (LockState.Response);
387+
rpc UnlockState(UnlockState.Request) returns (UnlockState.Response);
388+
rpc GetStates(GetStates.Request) returns (GetStates.Response);
389+
rpc DeleteState(DeleteState.Request) returns (DeleteState.Response);
390+
378391
//////// Graceful Shutdown
379392
rpc StopProvider(StopProvider.Request) returns (StopProvider.Response);
380393
}
@@ -426,6 +439,7 @@ message GetProviderSchema {
426439
map<string, Function> functions = 7;
427440
map<string, Schema> ephemeral_resource_schemas = 8;
428441
map<string, Schema> list_resource_schemas = 9;
442+
map<string, Schema> state_store_schemas = 10;
429443
repeated Diagnostic diagnostics = 4;
430444
Schema provider_meta = 5;
431445
ServerCapabilities server_capabilities = 6;
@@ -839,3 +853,95 @@ message ValidateListResourceConfig {
839853
repeated Diagnostic diagnostics = 1;
840854
}
841855
}
856+
857+
858+
message ValidateStorage {
859+
message Request {
860+
string type_name = 1;
861+
DynamicValue config = 2;
862+
}
863+
message Response {
864+
repeated Diagnostic diagnostics = 1;
865+
}
866+
}
867+
868+
message ConfigureStorage {
869+
message Request {
870+
string type_name = 1;
871+
DynamicValue prepared_config = 2;
872+
}
873+
message Response {
874+
repeated Diagnostic diagnostics = 1;
875+
}
876+
}
877+
878+
message ReadState {
879+
message Request {
880+
string type_name = 1;
881+
string state_id = 2;
882+
}
883+
message ResponseChunk {
884+
bytes data = 1;
885+
// supplied with the first chunk
886+
optional StateMeta meta = 2;
887+
}
888+
}
889+
890+
message WriteState {
891+
message RequestChunk {
892+
bytes data = 1;
893+
string state_id = 2;
894+
// supplied with the first chunk
895+
optional StateMeta meta = 3;
896+
}
897+
message Response {
898+
repeated Diagnostic diagnostics = 1;
899+
}
900+
}
901+
902+
message StateMeta {
903+
bytes checksum = 1;
904+
int64 number_of_chunks = 2;
905+
}
906+
907+
message LockState {
908+
message Request {
909+
string type_name = 1;
910+
string state_id = 2;
911+
string operation = 3;
912+
}
913+
message Response {
914+
string id = 1;
915+
repeated Diagnostic diagnostics = 2;
916+
}
917+
}
918+
919+
message UnlockState {
920+
message Request {
921+
string type_name = 1;
922+
string state_id = 2;
923+
string lock_id = 3;
924+
}
925+
message Response {
926+
repeated Diagnostic diagnostics = 1;
927+
}
928+
}
929+
930+
message GetStates {
931+
message Request {
932+
string type_name = 1;
933+
}
934+
message Response {
935+
repeated string state_id = 1;
936+
}
937+
}
938+
939+
message DeleteState {
940+
message Request {
941+
string type_name = 1;
942+
string state_id = 2;
943+
}
944+
message Response {
945+
repeated Diagnostic diagnostics = 1;
946+
}
947+
}

internal/builtin/providers/terraform/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (p *Provider) GetProviderSchema() providers.GetProviderSchemaResponse {
7373
ReturnType: cty.String,
7474
},
7575
},
76+
StateStores: map[string]providers.Schema{},
7677
}
7778
providers.SchemaCache.Set(tfaddr.NewProvider(tfaddr.BuiltInProviderHost, tfaddr.BuiltInProviderNamespace, "terraform"), resp)
7879
return resp
@@ -275,3 +276,9 @@ func (p *Provider) CallFunction(req providers.CallFunctionRequest) providers.Cal
275276
func (p *Provider) Close() error {
276277
return nil
277278
}
279+
280+
func (p *Provider) ValidateStorageConfig(req providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
281+
var resp providers.ValidateStorageConfigResponse
282+
resp.Diagnostics.Append(fmt.Errorf("unsupported storage type %q", req.TypeName))
283+
return resp
284+
}

internal/command/testing/test_provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ var (
9090
ReturnType: cty.Bool,
9191
},
9292
},
93+
// TODO - add a State Stores map here?
9394
}
9495
)
9596

internal/grpcwrap/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (p *provider) GetSchema(_ context.Context, req *tfplugin5.GetProviderSchema
4646
DataSourceSchemas: make(map[string]*tfplugin5.Schema),
4747
EphemeralResourceSchemas: make(map[string]*tfplugin5.Schema),
4848
ListResourceSchemas: make(map[string]*tfplugin5.Schema),
49+
StateStoreSchemas: make(map[string]*tfplugin5.Schema),
4950
}
5051

5152
resp.Provider = &tfplugin5.Schema{
@@ -86,6 +87,12 @@ func (p *provider) GetSchema(_ context.Context, req *tfplugin5.GetProviderSchema
8687
Block: convert.ConfigSchemaToProto(dat.Body),
8788
}
8889
}
90+
for typ, dat := range p.schema.StateStores {
91+
resp.StateStoreSchemas[typ] = &tfplugin5.Schema{
92+
Version: int64(dat.Version),
93+
Block: convert.ConfigSchemaToProto(dat.Body),
94+
}
95+
}
8996
if decls, err := convert.FunctionDeclsToProto(p.schema.Functions); err == nil {
9097
resp.Functions = decls
9198
} else {

internal/grpcwrap/provider6.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (p *provider6) GetProviderSchema(_ context.Context, req *tfplugin6.GetProvi
4848
EphemeralResourceSchemas: make(map[string]*tfplugin6.Schema),
4949
Functions: make(map[string]*tfplugin6.Function),
5050
ListResourceSchemas: make(map[string]*tfplugin6.Schema),
51+
StateStoreSchemas: make(map[string]*tfplugin6.Schema),
5152
}
5253

5354
resp.Provider = &tfplugin6.Schema{
@@ -88,6 +89,13 @@ func (p *provider6) GetProviderSchema(_ context.Context, req *tfplugin6.GetProvi
8889
Block: convert.ConfigSchemaToProto(dat.Body),
8990
}
9091
}
92+
93+
for typ, dat := range p.schema.StateStores {
94+
resp.StateStoreSchemas[typ] = &tfplugin6.Schema{
95+
Version: int64(dat.Version),
96+
Block: convert.ConfigSchemaToProto(dat.Body),
97+
}
98+
}
9199
if decls, err := convert.FunctionDeclsToProto(p.schema.Functions); err == nil {
92100
resp.Functions = decls
93101
} else {
@@ -814,6 +822,46 @@ func (p *provider6) ListResource(*tfplugin6.ListResource_Request, tfplugin6.Prov
814822
panic("not implemented")
815823
}
816824

825+
func (p *provider6) ValidateStorageConfig(ctx context.Context, req *tfplugin6.ValidateStorage_Request) (*tfplugin6.ValidateStorage_Response, error) {
826+
// TODO
827+
return nil, nil
828+
}
829+
830+
func (p *provider6) ConfigureStorage(ctx context.Context, req *tfplugin6.ConfigureStorage_Request) (*tfplugin6.ConfigureStorage_Response, error) {
831+
// TODO
832+
return nil, nil
833+
}
834+
835+
func (p *provider6) ReadState(req *tfplugin6.ReadState_Request, srv tfplugin6.Provider_ReadStateServer) error {
836+
// TODO
837+
return nil
838+
}
839+
840+
func (p *provider6) WriteState(srv tfplugin6.Provider_WriteStateServer) error {
841+
// TODO
842+
return nil
843+
}
844+
845+
func (p *provider6) LockState(ctx context.Context, req *tfplugin6.LockState_Request) (*tfplugin6.LockState_Response, error) {
846+
// TODO
847+
return nil, nil
848+
}
849+
850+
func (p *provider6) UnlockState(ctx context.Context, req *tfplugin6.UnlockState_Request) (*tfplugin6.UnlockState_Response, error) {
851+
// TODO
852+
return nil, nil
853+
}
854+
855+
func (p *provider6) GetStates(ctx context.Context, req *tfplugin6.GetStates_Request) (*tfplugin6.GetStates_Response, error) {
856+
// TODO
857+
return nil, nil
858+
}
859+
860+
func (p *provider6) DeleteState(ctx context.Context, req *tfplugin6.DeleteState_Request) (*tfplugin6.DeleteState_Response, error) {
861+
// TODO
862+
return nil, nil
863+
}
864+
817865
func (p *provider6) StopProvider(context.Context, *tfplugin6.StopProvider_Request) (*tfplugin6.StopProvider_Response, error) {
818866
resp := &tfplugin6.StopProvider_Response{}
819867
err := p.provider.Stop()

internal/plugin/grpc_provider.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func (p *GRPCProviderPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Serve
4646
return nil
4747
}
4848

49+
var _ providers.Interface = &GRPCProvider{}
50+
4951
// GRPCProvider handles the client, or core side of the plugin rpc connection.
5052
// The GRPCProvider methods are mostly a translation layer between the
5153
// terraform providers types and the grpc proto types, directly converting
@@ -102,6 +104,7 @@ func (p *GRPCProvider) GetProviderSchema() providers.GetProviderSchemaResponse {
102104
resp.DataSources = make(map[string]providers.Schema)
103105
resp.EphemeralResourceTypes = make(map[string]providers.Schema)
104106
resp.ListResourceTypes = make(map[string]providers.Schema)
107+
// TODO: resp.StateStores = make(map[string]providers.Schema)
105108

106109
// Some providers may generate quite large schemas, and the internal default
107110
// grpc response size limit is 4MB. 64MB should cover most any use case, and
@@ -1301,3 +1304,8 @@ func clientCapabilitiesToProto(c providers.ClientCapabilities) *proto.ClientCapa
13011304
WriteOnlyAttributesAllowed: c.WriteOnlyAttributesAllowed,
13021305
}
13031306
}
1307+
1308+
func (p *GRPCProvider) ValidateStorageConfig(r providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
1309+
// TODO
1310+
return providers.ValidateStorageConfigResponse{}
1311+
}

internal/plugin6/grpc_provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func (p *GRPCProviderPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Serve
4646
return nil
4747
}
4848

49+
var _ providers.Interface = &GRPCProvider{}
50+
4951
// GRPCProvider handles the client, or core side of the plugin rpc connection.
5052
// The GRPCProvider methods are mostly a translation layer between the
5153
// terraform providers types and the grpc proto types, directly converting
@@ -1246,6 +1248,11 @@ func (p *GRPCProvider) ListResource(r providers.ListResourceRequest) error {
12461248
panic("not implemented")
12471249
}
12481250

1251+
func (p *GRPCProvider) ValidateStorageConfig(r providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
1252+
// TODO
1253+
return providers.ValidateStorageConfigResponse{}
1254+
}
1255+
12491256
// closing the grpc connection is final, and terraform will call it at the end of every phase.
12501257
func (p *GRPCProvider) Close() error {
12511258
logger.Trace("GRPCProvider.v6: Close")

0 commit comments

Comments
 (0)