Skip to content

Commit 7b2f705

Browse files
committed
WIP
1 parent 86f0a9a commit 7b2f705

File tree

16 files changed

+353
-0
lines changed

16 files changed

+353
-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: 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")

internal/plugin6/mock_proto/mock.go

Lines changed: 160 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: 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
}

0 commit comments

Comments
 (0)