@@ -69,6 +69,8 @@ type BackendOpts struct {
6969 // during upgrade-triggered migrations.
7070 PreviousLocks * depsfile.Locks
7171
72+ SkipGetProviderSchemaCache bool
73+
7274 // ConfigOverride is an hcl.Body that, if non-nil, will be used with
7375 // configs.MergeBodies to override the type-specific backend configuration
7476 // arguments in Config.
@@ -374,7 +376,7 @@ func (m *Meta) BackendForLocalPlan(plan *plans.Plan) (backendrun.OperationsBacke
374376 return nil , diags
375377 }
376378
377- factories , err := m .ProviderFactoriesFromLocks (locks )
379+ factories , err := m .ProviderFactoriesFromLocks (locks , false )
378380 if err != nil {
379381 // This may happen if the provider isn't present in the provider cache.
380382 // This should be caught earlier by logic that diffs the config against the backend state file.
@@ -1224,7 +1226,7 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di
12241226 // AND we're not providing any overrides. An override can mean a change overriding an unchanged backend block (indicated by the hash value).
12251227 if (uint64 (cHash ) == s .StateStore .Hash ) && (! opts .Init || opts .ConfigOverride == nil ) {
12261228 log .Printf ("[TRACE] Meta.Backend: using already-initialized, unchanged %q state_store configuration" , stateStoreConfig .Type )
1227- savedStateStore , sssDiags := m .savedStateStore (sMgr , opts .Locks )
1229+ savedStateStore , sssDiags := m .savedStateStore (sMgr , opts .Locks , false )
12281230 diags = diags .Append (sssDiags )
12291231 // Verify that selected workspace exist. Otherwise prompt user to create one
12301232 if opts .Init && savedStateStore != nil {
@@ -1242,7 +1244,7 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di
12421244 // don't need to migrate, we update the state store cache hash value.
12431245 if ! m .stateStoreConfigNeedsMigration (stateStoreConfig , s .StateStore , opts ) {
12441246 log .Printf ("[TRACE] Meta.Backend: using already-initialized %q state store configuration" , stateStoreConfig .Type )
1245- savedStateStore , moreDiags := m .savedStateStore (sMgr , opts .Locks )
1247+ savedStateStore , moreDiags := m .savedStateStore (sMgr , opts .Locks , false )
12461248 diags = diags .Append (moreDiags )
12471249 if moreDiags .HasErrors () {
12481250 return nil , diags
@@ -1309,6 +1311,20 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di
13091311 return nil , diags
13101312 }
13111313
1314+ pLock := opts .Locks .Provider (stateStoreConfig .ProviderAddr )
1315+ lockVersion , err := providerreqs .GoVersionFromVersion (pLock .Version ())
1316+ if err != nil {
1317+ diags = diags .Append (tfdiags .Sourceless (
1318+ tfdiags .Warning ,
1319+ "Unable to determine version of the state store provider" ,
1320+ fmt .Sprintf ("Failed to parse version of %s from the lock file: %s" , stateStoreConfig .ProviderAddr .ForDisplay (), err ),
1321+ ))
1322+ return nil , diags
1323+ }
1324+ if ! lockVersion .Equal (s .StateStore .Provider .Version ) {
1325+ opts .SkipGetProviderSchemaCache = true
1326+ }
1327+
13121328 return m .stateStore_changed (stateStoreConfig , cHash , sMgr , opts , initReason )
13131329
13141330 default :
@@ -1497,7 +1513,7 @@ func (m *Meta) backendFromState(_ context.Context, locks *depsfile.Locks) (backe
14971513 // state_store
14981514 log .Printf ("[TRACE] Meta.Backend: working directory was previously initialized for %q state store" , s .StateStore .Type )
14991515 var ssDiags tfdiags.Diagnostics
1500- b , ssDiags = m .savedStateStore (sMgr , locks ) // Relies on the state manager's internal state being refreshed above.
1516+ b , ssDiags = m .savedStateStore (sMgr , locks , false ) // Relies on the state manager's internal state being refreshed above.
15011517 diags = diags .Append (ssDiags )
15021518 if ssDiags .HasErrors () {
15031519 return nil , diags
@@ -2545,7 +2561,7 @@ func (m *Meta) stateStore_to_backend(ssSMgr *clistate.LocalState, dstBackendType
25452561 view .Output (views .StateMigrateLocalMessage , stateStoreType )
25462562
25472563 // Initialize the configured state store
2548- ss , moreDiags := m .savedStateStore (ssSMgr , opts .Locks )
2564+ ss , moreDiags := m .savedStateStore (ssSMgr , opts .Locks , false )
25492565 diags = diags .Append (moreDiags )
25502566 if moreDiags .HasErrors () {
25512567 return nil , diags
@@ -2672,7 +2688,7 @@ func (m *Meta) stateStore_changed(cfg *configs.StateStore, cfgHash int, sMgr *cl
26722688 }
26732689
26742690 // Grab the source state store
2675- srcB , srcBDiags := m .savedStateStore (sMgr , opts .PreviousLocks )
2691+ srcB , srcBDiags := m .savedStateStore (sMgr , opts .PreviousLocks , opts . SkipGetProviderSchemaCache )
26762692 diags = diags .Append (srcBDiags )
26772693 if srcBDiags .HasErrors () {
26782694 return nil , diags
@@ -2689,11 +2705,12 @@ func (m *Meta) stateStore_changed(cfg *configs.StateStore, cfgHash int, sMgr *cl
26892705
26902706 // Perform the migration
26912707 err := m .backendMigrateState (& backendMigrateOpts {
2692- SourceType : s .StateStore .Type ,
2693- DestinationType : cfg .Type ,
2694- Source : srcB ,
2695- Destination : dstB ,
2696- ViewType : vt ,
2708+ SkipGetProviderSchemaCache : opts .SkipGetProviderSchemaCache ,
2709+ SourceType : s .StateStore .Type ,
2710+ DestinationType : cfg .Type ,
2711+ Source : srcB ,
2712+ Destination : dstB ,
2713+ ViewType : vt ,
26972714 })
26982715 if err != nil {
26992716 diags = diags .Append (err )
@@ -2826,7 +2843,7 @@ To make the initial dependency selections that will initialize the dependency lo
28262843}
28272844
28282845// Initializing a saved state store from the backend state file (aka 'cache file', aka 'legacy state file')
2829- func (m * Meta ) savedStateStore (sMgr * clistate.LocalState , locks * depsfile.Locks ) (backend.Backend , tfdiags.Diagnostics ) {
2846+ func (m * Meta ) savedStateStore (sMgr * clistate.LocalState , locks * depsfile.Locks , skipCache bool ) (backend.Backend , tfdiags.Diagnostics ) {
28302847 // We're preparing a state_store version of backend.Backend.
28312848 //
28322849 // The provider and state store will be configured using the backend state file.
@@ -2835,7 +2852,7 @@ func (m *Meta) savedStateStore(sMgr *clistate.LocalState, locks *depsfile.Locks)
28352852
28362853 s := sMgr .State ()
28372854
2838- factory , pDiags := m .StateStoreProviderFactoryFromConfigState (s .StateStore , locks )
2855+ factory , pDiags := m .StateStoreProviderFactoryFromConfigState (s .StateStore , locks , skipCache )
28392856 diags = diags .Append (pDiags )
28402857 if pDiags .HasErrors () {
28412858 return nil , diags
@@ -3317,7 +3334,7 @@ func (m *Meta) StateStoreProviderFactoryFromConfig(config *configs.StateStore, l
33173334 })
33183335 }
33193336
3320- factories , err := m .ProviderFactoriesFromLocks (locks )
3337+ factories , err := m .ProviderFactoriesFromLocks (locks , false )
33213338 if err != nil {
33223339 // This may happen if the provider isn't present in the provider cache.
33233340 // This should be caught earlier by logic that diffs the config against the backend state file.
@@ -3350,7 +3367,7 @@ func (m *Meta) StateStoreProviderFactoryFromConfig(config *configs.StateStore, l
33503367 return factory , diags
33513368}
33523369
3353- func (m * Meta ) StateStoreProviderFactoryFromConfigState (cfgState * workdir.StateStoreConfigState , locks * depsfile.Locks ) (providers.Factory , tfdiags.Diagnostics ) {
3370+ func (m * Meta ) StateStoreProviderFactoryFromConfigState (cfgState * workdir.StateStoreConfigState , locks * depsfile.Locks , skipCache bool ) (providers.Factory , tfdiags.Diagnostics ) {
33543371 var diags tfdiags.Diagnostics
33553372
33563373 if cfgState == nil {
@@ -3366,7 +3383,7 @@ func (m *Meta) StateStoreProviderFactoryFromConfigState(cfgState *workdir.StateS
33663383 })
33673384 }
33683385
3369- factories , err := m .providerFactoriesFromLocks (locks )
3386+ factories , err := m .providerFactoriesFromLocks (locks , skipCache )
33703387 if err != nil {
33713388 // This may happen if the provider isn't present in the provider cache.
33723389 // This should be caught earlier by logic that diffs the config against the backend state file.
0 commit comments