Skip to content

Commit 09139d6

Browse files
committed
WIP
1 parent c7be9f7 commit 09139d6

File tree

8 files changed

+55
-0
lines changed

8 files changed

+55
-0
lines changed

internal/builtin/providers/terraform/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,9 @@ func (p *Provider) ConfigureStateStore(req providers.ConfigureStateStoreRequest)
294294
func (p *Provider) Close() error {
295295
return nil
296296
}
297+
298+
func (p *Provider) ValidateStorageConfig(req providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
299+
var resp providers.ValidateStorageConfigResponse
300+
resp.Diagnostics.Append(fmt.Errorf("unsupported storage type %q", req.TypeName))
301+
return resp
302+
}

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/plugin/grpc_provider.go

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

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

107110
// Some providers may generate quite large schemas, and the internal default
108111
// grpc response size limit is 4MB. 64MB should cover most any use case, and
@@ -1407,3 +1410,8 @@ func clientCapabilitiesToProto(c providers.ClientCapabilities) *proto.ClientCapa
14071410
WriteOnlyAttributesAllowed: c.WriteOnlyAttributesAllowed,
14081411
}
14091412
}
1413+
1414+
func (p *GRPCProvider) ValidateStorageConfig(r providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
1415+
// TODO
1416+
return providers.ValidateStorageConfigResponse{}
1417+
}

internal/plugin6/grpc_provider.go

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

50+
var _ providers.Interface = &GRPCProvider{}
51+
5052
// GRPCProvider handles the client, or core side of the plugin rpc connection.
5153
// The GRPCProvider methods are mostly a translation layer between the
5254
// terraform providers types and the grpc proto types, directly converting
@@ -1353,6 +1355,11 @@ func (p *GRPCProvider) ConfigureStateStore(r providers.ConfigureStateStoreReques
13531355
panic("not implemented")
13541356
}
13551357

1358+
func (p *GRPCProvider) ValidateStorageConfig(r providers.ValidateStorageConfigRequest) providers.ValidateStorageConfigResponse {
1359+
// TODO
1360+
return providers.ValidateStorageConfigResponse{}
1361+
}
1362+
13561363
// closing the grpc connection is final, and terraform will call it at the end of every phase.
13571364
func (p *GRPCProvider) Close() error {
13581365
logger.Trace("GRPCProvider.v6: Close")

internal/provider-simple-v6/provider.go

Lines changed: 2 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{

internal/provider-simple/provider.go

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

internal/providers/provider.go

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

119+
// ReadState(ReadStateRequest, srv ProviderReadStateServer)
120+
// WriteState(srv ProviderWriteStateServer)
121+
122+
// LockState(LockStateRequest) LockStateResponse
123+
// UnlockState(UnlockStateRequest) UnlockStateResponse
124+
// GetStates(GetStatesRequest) GetStatesResponse
125+
// DeleteState(DeleteStateRequest) DeleteStateResponse
126+
119127
// Close shuts down the plugin process if applicable.
120128
Close() error
121129
}
@@ -786,3 +794,16 @@ type ConfigureStateStoreResponse struct {
786794
// Diagnostics contains any warnings or errors from the method call.
787795
Diagnostics tfdiags.Diagnostics
788796
}
797+
798+
type ValidateStorageConfigRequest struct {
799+
// TypeName is the name of the storage type to validate.
800+
TypeName string
801+
802+
// Config is the configuration value to validate.
803+
Config cty.Value
804+
}
805+
806+
type ValidateStorageConfigResponse struct {
807+
// Diagnostics contains any warnings or errors from the method call.
808+
Diagnostics tfdiags.Diagnostics
809+
}

0 commit comments

Comments
 (0)