@@ -196,13 +196,13 @@ func (m *Meta) Backend(opts *BackendOpts) (backendrun.OperationsBackend, tfdiags
196
196
// the user, since the local backend should only be used when learning or
197
197
// in exceptional cases and so it's better to help the user learn that
198
198
// by introducing it as a concept.
199
- if m .backendState == nil {
199
+ if m .backendConfigState == nil {
200
200
// NOTE: This synthetic object is intentionally _not_ retained in the
201
201
// on-disk record of the backend configuration, which was already dealt
202
202
// with inside backendFromConfig, because we still need that codepath
203
203
// to be able to recognize the lack of a config as distinct from
204
204
// explicitly setting local until we do some more refactoring here.
205
- m .backendState = & workdir.BackendConfigState {
205
+ m .backendConfigState = & workdir.BackendConfigState {
206
206
Type : "local" ,
207
207
ConfigRaw : json .RawMessage ("{}" ),
208
208
}
@@ -412,13 +412,34 @@ func (m *Meta) Operation(b backend.Backend, vt arguments.ViewType) *backendrun.O
412
412
// here first is a bug, so panic.
413
413
panic (fmt .Sprintf ("invalid workspace: %s" , err ))
414
414
}
415
- planOutBackend , err := m .backendState .Plan (schema , workspace )
416
- if err != nil {
417
- // Always indicates an implementation error in practice, because
418
- // errors here indicate invalid encoding of the backend configuration
419
- // in memory, and we should always have validated that by the time
420
- // we get here.
421
- panic (fmt .Sprintf ("failed to encode backend configuration for plan: %s" , err ))
415
+
416
+ var planOutBackend * plans.Backend
417
+ var planOutStateStore * plans.StateStore
418
+ switch {
419
+ case m .backendConfigState == nil && m .stateStoreConfigState == nil :
420
+ // Neither set
421
+ panic (fmt .Sprintf ("failed to encode backend configuration for plan: neither backend nor state_store data present" ))
422
+ case m .backendConfigState != nil && m .stateStoreConfigState != nil :
423
+ // Both set
424
+ panic (fmt .Sprintf ("failed to encode backend configuration for plan: both backend and state_store data present but they are mutually exclusive" ))
425
+ case m .backendConfigState != nil :
426
+ planOutBackend , err = m .backendConfigState .Plan (schema , workspace )
427
+ if err != nil {
428
+ // Always indicates an implementation error in practice, because
429
+ // errors here indicate invalid encoding of the backend configuration
430
+ // in memory, and we should always have validated that by the time
431
+ // we get here.
432
+ panic (fmt .Sprintf ("failed to encode backend configuration for plan: %s" , err ))
433
+ }
434
+ case m .stateStoreConfigState != nil :
435
+ planOutStateStore , err = m .stateStoreConfigState .Plan (schema , workspace )
436
+ if err != nil {
437
+ // Always indicates an implementation error in practice, because
438
+ // errors here indicate invalid encoding of the state_store configuration
439
+ // in memory, and we should always have validated that by the time
440
+ // we get here.
441
+ panic (fmt .Sprintf ("failed to encode state_store configuration for plan: %s" , err ))
442
+ }
422
443
}
423
444
424
445
stateLocker := clistate .NewNoopLocker ()
@@ -438,7 +459,12 @@ func (m *Meta) Operation(b backend.Backend, vt arguments.ViewType) *backendrun.O
438
459
}
439
460
440
461
return & backendrun.Operation {
441
- PlanOutBackend : planOutBackend ,
462
+
463
+ // These two fields are mutually exclusive,
464
+ // and one is being assigned a nil value below.
465
+ PlanOutBackend : planOutBackend ,
466
+ PlanOutStateStore : planOutStateStore ,
467
+
442
468
Targets : m .targets ,
443
469
UIIn : m .UIInput (),
444
470
UIOut : m .Ui ,
@@ -578,10 +604,10 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di
578
604
579
605
// Upon return, we want to set the state we're using in-memory so that
580
606
// we can access it for commands.
581
- m .backendState = nil
607
+ m .backendConfigState = nil
582
608
defer func () {
583
609
if s := sMgr .State (); s != nil && ! s .Backend .Empty () {
584
- m .backendState = s .Backend
610
+ m .backendConfigState = s .Backend
585
611
}
586
612
}()
587
613
0 commit comments