Skip to content

Commit c833aa7

Browse files
committed
WIP
1 parent 32a9788 commit c833aa7

File tree

15 files changed

+194
-0
lines changed

15 files changed

+194
-0
lines changed

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: 49 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,7 @@ func (p *provider6) ListResource(*tfplugin6.ListResource_Request, tfplugin6.Prov
814822
panic("not implemented")
815823
}
816824

825+
<<<<<<< HEAD
817826
func (p *provider6) ValidateStateStoreConfig(ctx context.Context, req *tfplugin6.ValidateStateStore_Request) (*tfplugin6.ValidateStateStore_Response, error) {
818827
panic("not implemented")
819828
}
@@ -844,6 +853,46 @@ func (p *provider6) GetStates(ctx context.Context, req *tfplugin6.GetStates_Requ
844853

845854
func (p *provider6) DeleteState(ctx context.Context, req *tfplugin6.DeleteState_Request) (*tfplugin6.DeleteState_Response, error) {
846855
panic("not implemented")
856+
=======
857+
func (p *provider6) ValidateStorageConfig(ctx context.Context, req *tfplugin6.ValidateStorage_Request) (*tfplugin6.ValidateStorage_Response, error) {
858+
// TODO
859+
return nil, nil
860+
}
861+
862+
func (p *provider6) ConfigureStorage(ctx context.Context, req *tfplugin6.ConfigureStorage_Request) (*tfplugin6.ConfigureStorage_Response, error) {
863+
// TODO
864+
return nil, nil
865+
}
866+
867+
func (p *provider6) ReadState(req *tfplugin6.ReadState_Request, srv tfplugin6.Provider_ReadStateServer) error {
868+
// TODO
869+
return nil
870+
}
871+
872+
func (p *provider6) WriteState(srv tfplugin6.Provider_WriteStateServer) error {
873+
// TODO
874+
return nil
875+
}
876+
877+
func (p *provider6) LockState(ctx context.Context, req *tfplugin6.LockState_Request) (*tfplugin6.LockState_Response, error) {
878+
// TODO
879+
return nil, nil
880+
}
881+
882+
func (p *provider6) UnlockState(ctx context.Context, req *tfplugin6.UnlockState_Request) (*tfplugin6.UnlockState_Response, error) {
883+
// TODO
884+
return nil, nil
885+
}
886+
887+
func (p *provider6) GetStates(ctx context.Context, req *tfplugin6.GetStates_Request) (*tfplugin6.GetStates_Response, error) {
888+
// TODO
889+
return nil, nil
890+
}
891+
892+
func (p *provider6) DeleteState(ctx context.Context, req *tfplugin6.DeleteState_Request) (*tfplugin6.DeleteState_Response, error) {
893+
// TODO
894+
return nil, nil
895+
>>>>>>> d7931111d1 (WIP)
847896
}
848897

849898
func (p *provider6) StopProvider(context.Context, *tfplugin6.StopProvider_Request) (*tfplugin6.StopProvider_Response, error) {

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")

internal/provider-simple-v6/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type simple struct {
2121
schema providers.GetProviderSchemaResponse
2222
}
2323

24+
var _ providers.Interface = simple{}
25+
2426
func Provider() providers.Interface {
2527
simpleResource := providers.Schema{
2628
Body: &configschema.Block{
@@ -251,6 +253,11 @@ func (s simple) CallFunction(req providers.CallFunctionRequest) (resp providers.
251253
return resp
252254
}
253255

256+
func (s simple) ValidateStorageConfig(req providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
257+
// TODO
258+
return providers.ValidateStorageConfigResponse{}
259+
}
260+
254261
func (s simple) Close() error {
255262
return nil
256263
}

internal/provider-simple/provider.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func Provider() providers.Interface {
4949
EphemeralResourceTypes: map[string]providers.Schema{
5050
"simple_resource": simpleResource,
5151
},
52+
StateStores: map[string]providers.Schema{
53+
"simple_store": simpleResource,
54+
},
5255
ServerCapabilities: providers.ServerCapabilities{
5356
PlanDestroy: true,
5457
},
@@ -211,6 +214,12 @@ func (s simple) CallFunction(req providers.CallFunctionRequest) (resp providers.
211214
panic("CallFunction on provider that didn't declare any functions")
212215
}
213216

217+
func (s simple) ValidateStorageConfig(req providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
218+
// Our schema doesn't include any storages, so it should be impossible
219+
// to get in here.
220+
panic("ValidateStorageConfig on provider that didn't declare any storages")
221+
}
222+
214223
func (s simple) Close() error {
215224
return nil
216225
}

internal/providers/mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ func (m *Mock) CallFunction(request CallFunctionRequest) CallFunctionResponse {
413413
return m.Provider.CallFunction(request)
414414
}
415415

416+
func (m *Mock) ValidateStorageConfig(req ValidateStorageConfigRequest) ValidateStorageConfigResponse {
417+
return m.Provider.ValidateStorageConfig(req)
418+
}
419+
416420
func (m *Mock) Close() error {
417421
return m.Provider.Close()
418422
}

internal/providers/provider.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ type Interface interface {
104104
// CallFunction calls a provider-contributed function.
105105
CallFunction(CallFunctionRequest) CallFunctionResponse
106106

107+
// ValidateStorageConfig allows the provider to validate storage configuration values
108+
ValidateStorageConfig(ValidateStorageConfigRequest) ValidateStorageConfigResponse
109+
// ConfigureStorage(ConfigureStorageRequest) ConfigureStorageResponse
110+
111+
// ReadState(ReadStateRequest, srv ProviderReadStateServer)
112+
// WriteState(srv ProviderWriteStateServer)
113+
114+
// LockState(LockStateRequest) LockStateResponse
115+
// UnlockState(UnlockStateRequest) UnlockStateResponse
116+
// GetStates(GetStatesRequest) GetStatesResponse
117+
// DeleteState(DeleteStateRequest) DeleteStateResponse
118+
107119
// Close shuts down the plugin process if applicable.
108120
Close() error
109121
}
@@ -138,6 +150,9 @@ type GetProviderSchemaResponse struct {
138150
// prefix) to the declaration of a function.
139151
Functions map[string]FunctionDecl
140152

153+
// StateStores maps the backend type name to that type's schema.
154+
StateStores map[string]Schema
155+
141156
// Diagnostics contains any warnings or errors from the method call.
142157
Diagnostics tfdiags.Diagnostics
143158

@@ -721,3 +736,16 @@ type ListResourceRequest struct {
721736
// the full resource object for each result
722737
IncludeResourceObject bool
723738
}
739+
740+
type ValidateStorageConfigRequest struct {
741+
// TypeName is the name of the storage type to validate.
742+
TypeName string
743+
744+
// Config is the configuration value to validate.
745+
Config cty.Value
746+
}
747+
748+
type ValidateStorageConfigResponse struct {
749+
// Diagnostics contains any warnings or errors from the method call.
750+
Diagnostics tfdiags.Diagnostics
751+
}

0 commit comments

Comments
 (0)