Skip to content

Commit 70a7741

Browse files
committed
Implement initialising an uninitialised dir with PSS
1 parent 7753904 commit 70a7741

File tree

6 files changed

+456
-10
lines changed

6 files changed

+456
-10
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (c *InitCommand) initCloud(ctx context.Context, root *configs.Module, extra
159159
return back, true, diags
160160
}
161161

162-
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) {
162+
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) {
163163
ctx, span := tracer.Start(ctx, "initialize backend")
164164
_ = ctx // prevent staticcheck from complaining to avoid a maintenance hazard of having the wrong ctx in scope here
165165
defer span.End()
@@ -272,6 +272,7 @@ func (c *InitCommand) initBackend(ctx context.Context, root *configs.Module, ext
272272

273273
opts = &BackendOpts{
274274
StateStoreConfig: root.StateStore,
275+
Locks: locks,
275276
ProviderFactory: factory,
276277
ConfigOverride: configOverride,
277278
Init: true,

internal/command/init_run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hashicorp/terraform/internal/command/arguments"
1414
"github.com/hashicorp/terraform/internal/command/views"
1515
"github.com/hashicorp/terraform/internal/configs"
16+
"github.com/hashicorp/terraform/internal/depsfile"
1617
"github.com/hashicorp/terraform/internal/states"
1718
"github.com/hashicorp/terraform/internal/terraform"
1819
"github.com/hashicorp/terraform/internal/tfdiags"
@@ -153,7 +154,8 @@ func (c *InitCommand) run(initArgs *arguments.Init, view views.Init) int {
153154
case initArgs.Cloud && rootModEarly.CloudConfig != nil:
154155
back, backendOutput, backDiags = c.initCloud(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, view)
155156
case initArgs.Backend:
156-
back, backendOutput, backDiags = c.initBackend(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, view)
157+
var locks *depsfile.Locks // Empty locks- this value is unused when a `backend` is used (vs. a `state_store`)
158+
back, backendOutput, backDiags = c.initBackend(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, locks, view)
157159
default:
158160
// load the previously-stored backend config
159161
back, backDiags = c.Meta.backendFromState(ctx)

internal/command/init_run_experiment.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,10 @@ func (c *InitCommand) runPssInit(initArgs *arguments.Init, view views.Init) int
205205
case initArgs.Cloud && rootModEarly.CloudConfig != nil:
206206
back, backendOutput, backDiags = c.initCloud(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, view)
207207
case initArgs.Backend:
208-
// TODO(SarahFrench/radeksimko) - pass information about config locks (`configLocks`) into initBackend to
209-
// enable PSS
210-
back, backendOutput, backDiags = c.initBackend(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, view)
208+
// This handles case when config contains either backend or state_store blocks.
209+
// This is valid as either can be implementations of backend.Backend, which is what we
210+
// obtain here.
211+
back, backendOutput, backDiags = c.initBackend(ctx, rootModEarly, initArgs.BackendConfig, initArgs.ViewType, configLocks, view)
211212
default:
212213
// load the previously-stored backend config
213214
back, backDiags = c.Meta.backendFromState(ctx)

0 commit comments

Comments
 (0)