Skip to content

Commit f3221a2

Browse files
committed
Implement initialising an uninitialised dir with PSS
1 parent 8ca1b58 commit f3221a2

File tree

4 files changed

+455
-7
lines changed

4 files changed

+455
-7
lines changed

internal/backend/pluggable/pluggable.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ func (p *Pluggable) ConfigSchema() *configschema.Block {
6868
return val.Body
6969
}
7070

71+
// ProviderSchema returns the schema for the provider implementing the state store.
72+
//
73+
// This isn't part of the backend.Backend interface but is needed in calling code.
74+
// When it's used the backend.Backend will need to be cast to a Pluggable.
75+
func (p *Pluggable) ProviderSchema() *configschema.Block {
76+
schemaResp := p.provider.GetProviderSchema()
77+
return schemaResp.Provider.Body
78+
}
79+
7180
// PrepareConfig validates configuration for the state store in
7281
// the state storage provider. The configuration sent from Terraform core
7382
// will not include any values from environment variables; it is the

internal/command/init.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/hashicorp/terraform/internal/command/views"
3131
"github.com/hashicorp/terraform/internal/configs"
3232
"github.com/hashicorp/terraform/internal/configs/configschema"
33+
"github.com/hashicorp/terraform/internal/depsfile"
3334
"github.com/hashicorp/terraform/internal/didyoumean"
3435
"github.com/hashicorp/terraform/internal/getproviders"
3536
"github.com/hashicorp/terraform/internal/providercache"
@@ -187,7 +188,11 @@ func (c *InitCommand) Run(args []string) int {
187188
case initArgs.Cloud && rootModEarly.CloudConfig != nil:
188189
back, backendOutput, backDiags = c.initCloud(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, view)
189190
case initArgs.Backend:
190-
back, backendOutput, backDiags = c.initBackend(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, view)
191+
// This handles case when config contains either backend or state_store blocks.
192+
// This is valid as either can be implementations of backend.Backend, which is what we
193+
// obtain here.
194+
var locks *depsfile.Locks
195+
back, backendOutput, backDiags = c.initBackend(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, locks, view)
191196
default:
192197
// load the previously-stored backend config
193198
back, backDiags = c.Meta.backendFromState(ctx)
@@ -420,7 +425,7 @@ func (c *InitCommand) initCloud(ctx context.Context, root *configs.Module, extra
420425
return back, true, diags
421426
}
422427

423-
func (c *InitCommand) initBackend(ctx context.Context, root *configs.Module, extraConfig arguments.FlagNameValueSlice, viewType arguments.ViewType, view views.Init) (be backend.Backend, output bool, diags tfdiags.Diagnostics) {
428+
func (c *InitCommand) initBackend(ctx context.Context, root *configs.Module, extraConfig arguments.FlagNameValueSlice, viewType arguments.ViewType, locks *depsfile.Locks, view views.Init) (be backend.Backend, output bool, diags tfdiags.Diagnostics) {
424429
ctx, span := tracer.Start(ctx, "initialize backend")
425430
_ = ctx // prevent staticcheck from complaining to avoid a maintenence hazard of having the wrong ctx in scope here
426431
defer span.End()
@@ -534,6 +539,7 @@ func (c *InitCommand) initBackend(ctx context.Context, root *configs.Module, ext
534539

535540
opts = &BackendOpts{
536541
StateStoreConfig: root.StateStore,
542+
Locks: locks,
537543
ProviderFactory: factory,
538544
ConfigOverride: configOverride,
539545
Init: true,

0 commit comments

Comments
 (0)