@@ -986,18 +986,13 @@ func (c *InitCommand) getProvidersFromState(ctx context.Context, state *states.S
986
986
ctx = evts .OnContext (ctx )
987
987
988
988
mode := providercache .InstallNewProvidersOnly
989
- if upgrade {
990
- if flagLockfile == "readonly" {
991
- diags = diags .Append (fmt .Errorf ("The -upgrade flag conflicts with -lockfile=readonly." ))
992
- view .Diagnostics (diags )
993
- return true , nil , diags
994
- }
995
989
996
- // We don't set `mode = providercache.InstallUpgrades` here when downloading providers from
997
- // state, as it'll cause Terraform to download provider versions that don't match version
998
- // constraints in the config.
999
- // Instead, leave `mode` as `providercache.InstallNewProvidersOnly`.
1000
- }
990
+ // We don't handle upgrade flags here, i.e. what happens at this point in getProvidersFromConfig:
991
+ // > We cannot upgrade a provider used only by the state, as there are no version constraints in state.
992
+ // > Given the overlap between providers in the config and state, using the upgrade mode here
993
+ // would remove the effects of version constraints from the config.
994
+ // > Any validation of CLI flag usage is already done in getProvidersFromConfig
995
+
1001
996
newLocks , err := inst .EnsureProviderVersions (ctx , inProgressLocks , reqs , mode )
1002
997
if ctx .Err () == context .Canceled {
1003
998
diags = diags .Append (fmt .Errorf ("Provider installation was canceled by an interrupt signal." ))
0 commit comments