Skip to content

Commit fd74a25

Browse files
Update get provider schema to include state store information (#36834)
* Update `GetProviderSchema` in .proto files to include state store schemas * make protobuf * Update GetProviderSchemaResponse struct * `terraform` provider reports it has no state stores * Update grpcwrap * Uncertain TODO comments * Apply suggestions from code review Co-authored-by: Radek Simko <[email protected]> * Update to StateStoreSchemas * make protobuf * Update to "StateStoreSchemas" * Add ephemeral resource and state store processing to protocol 5 grpcwrap * fix name in comment --------- Co-authored-by: Radek Simko <[email protected]> Co-authored-by: Radek Simko <[email protected]>
1 parent b54b90e commit fd74a25

File tree

11 files changed

+2306
-2241
lines changed

11 files changed

+2306
-2241
lines changed

docs/plugin-protocol/tfplugin5.10.proto

+1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ message GetProviderSchema {
412412
map<string, Schema> data_source_schemas = 3;
413413
map<string, Function> functions = 7;
414414
map<string, Schema> ephemeral_resource_schemas = 8;
415+
map<string, Schema> state_store_schemas = 9;
415416
repeated Diagnostic diagnostics = 4;
416417
Schema provider_meta = 5;
417418
ServerCapabilities server_capabilities = 6;

docs/plugin-protocol/tfplugin6.10.proto

+1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ message GetProviderSchema {
430430
map<string, Schema> data_source_schemas = 3;
431431
map<string, Function> functions = 7;
432432
map<string, Schema> ephemeral_resource_schemas = 8;
433+
map<string, Schema> state_store_schemas = 9;
433434
repeated Diagnostic diagnostics = 4;
434435
Schema provider_meta = 5;
435436
ServerCapabilities server_capabilities = 6;

internal/builtin/providers/terraform/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func (p *Provider) GetProviderSchema() providers.GetProviderSchemaResponse {
7272
ReturnType: cty.String,
7373
},
7474
},
75+
StateStoreSchemas: map[string]providers.Schema{},
7576
}
7677
providers.SchemaCache.Set(tfaddr.NewProvider(tfaddr.BuiltInProviderHost, tfaddr.BuiltInProviderNamespace, "terraform"), resp)
7778
return resp

internal/command/testing/test_provider.go

+1
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

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (p *provider) GetSchema(_ context.Context, req *tfplugin5.GetProviderSchema
4545
ResourceSchemas: make(map[string]*tfplugin5.Schema),
4646
DataSourceSchemas: make(map[string]*tfplugin5.Schema),
4747
EphemeralResourceSchemas: make(map[string]*tfplugin5.Schema),
48+
StateStoreSchemas: make(map[string]*tfplugin5.Schema),
4849
}
4950

5051
resp.Provider = &tfplugin5.Schema{
@@ -79,6 +80,12 @@ func (p *provider) GetSchema(_ context.Context, req *tfplugin5.GetProviderSchema
7980
Block: convert.ConfigSchemaToProto(dat.Body),
8081
}
8182
}
83+
for typ, dat := range p.schema.StateStoreSchemas {
84+
resp.StateStoreSchemas[typ] = &tfplugin5.Schema{
85+
Version: int64(dat.Version),
86+
Block: convert.ConfigSchemaToProto(dat.Body),
87+
}
88+
}
8289
if decls, err := convert.FunctionDeclsToProto(p.schema.Functions); err == nil {
8390
resp.Functions = decls
8491
} else {

internal/grpcwrap/provider6.go

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (p *provider6) GetProviderSchema(_ context.Context, req *tfplugin6.GetProvi
4747
DataSourceSchemas: make(map[string]*tfplugin6.Schema),
4848
EphemeralResourceSchemas: make(map[string]*tfplugin6.Schema),
4949
Functions: make(map[string]*tfplugin6.Function),
50+
StateStoreSchemas: make(map[string]*tfplugin6.Schema),
5051
}
5152

5253
resp.Provider = &tfplugin6.Schema{
@@ -81,6 +82,12 @@ func (p *provider6) GetProviderSchema(_ context.Context, req *tfplugin6.GetProvi
8182
Block: convert.ConfigSchemaToProto(dat.Body),
8283
}
8384
}
85+
for typ, dat := range p.schema.StateStoreSchemas {
86+
resp.StateStoreSchemas[typ] = &tfplugin6.Schema{
87+
Version: int64(dat.Version),
88+
Block: convert.ConfigSchemaToProto(dat.Body),
89+
}
90+
}
8491
if decls, err := convert.FunctionDeclsToProto(p.schema.Functions); err == nil {
8592
resp.Functions = decls
8693
} else {

internal/providers/provider.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ type GetProviderSchemaResponse struct {
142142
// prefix) to the declaration of a function.
143143
Functions map[string]FunctionDecl
144144

145-
// TODO
146-
// Backends maps the backend type name to that type's schema.
147-
// Backends map[string]Schema
145+
// StateStoreSchemas maps the backend type name to that type's schema.
146+
StateStoreSchemas map[string]Schema
148147

149148
// Diagnostics contains any warnings or errors from the method call.
150149
Diagnostics tfdiags.Diagnostics

internal/providers/testing/provider_mock.go

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func (p *MockProvider) getProviderSchema() providers.GetProviderSchemaResponse {
149149
Provider: providers.Schema{},
150150
DataSources: map[string]providers.Schema{},
151151
ResourceTypes: map[string]providers.Schema{},
152+
// TODO - any update needed here?
152153
}
153154
}
154155

internal/stacks/stackruntime/testing/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func NewProviderWithData(t *testing.T, store *ResourceStore) *MockProvider {
210210
ServerCapabilities: providers.ServerCapabilities{
211211
MoveResourceState: true,
212212
},
213+
// TODO - state store here?
213214
},
214215
PlanResourceChangeFn: func(request providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
215216
return getResource(request.TypeName).Plan(request, store)

0 commit comments

Comments
 (0)