@@ -196,13 +196,13 @@ func (m *Meta) Backend(opts *BackendOpts) (backendrun.OperationsBackend, tfdiags
196196 // the user, since the local backend should only be used when learning or
197197 // in exceptional cases and so it's better to help the user learn that
198198 // by introducing it as a concept.
199- if m .backendState == nil {
199+ if m .backendConfigState == nil {
200200 // NOTE: This synthetic object is intentionally _not_ retained in the
201201 // on-disk record of the backend configuration, which was already dealt
202202 // with inside backendFromConfig, because we still need that codepath
203203 // to be able to recognize the lack of a config as distinct from
204204 // explicitly setting local until we do some more refactoring here.
205- m .backendState = & workdir.BackendConfigState {
205+ m .backendConfigState = & workdir.BackendConfigState {
206206 Type : "local" ,
207207 ConfigRaw : json .RawMessage ("{}" ),
208208 }
@@ -412,13 +412,34 @@ func (m *Meta) Operation(b backend.Backend, vt arguments.ViewType) *backendrun.O
412412 // here first is a bug, so panic.
413413 panic (fmt .Sprintf ("invalid workspace: %s" , err ))
414414 }
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+ }
422443 }
423444
424445 stateLocker := clistate .NewNoopLocker ()
@@ -438,7 +459,12 @@ func (m *Meta) Operation(b backend.Backend, vt arguments.ViewType) *backendrun.O
438459 }
439460
440461 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+
442468 Targets : m .targets ,
443469 UIIn : m .UIInput (),
444470 UIOut : m .Ui ,
@@ -578,10 +604,10 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di
578604
579605 // Upon return, we want to set the state we're using in-memory so that
580606 // we can access it for commands.
581- m .backendState = nil
607+ m .backendConfigState = nil
582608 defer func () {
583609 if s := sMgr .State (); s != nil && ! s .Backend .Empty () {
584- m .backendState = s .Backend
610+ m .backendConfigState = s .Backend
585611 }
586612 }()
587613
0 commit comments