Skip to content

Commit db3bd03

Browse files
committed
fix: completely remove use of upgrade flag in getProvidersFromState
1 parent 11d90bc commit db3bd03

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

internal/command/init.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -986,18 +986,13 @@ func (c *InitCommand) getProvidersFromState(ctx context.Context, state *states.S
986986
ctx = evts.OnContext(ctx)
987987

988988
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-
}
995989

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+
1001996
newLocks, err := inst.EnsureProviderVersions(ctx, inProgressLocks, reqs, mode)
1002997
if ctx.Err() == context.Canceled {
1003998
diags = diags.Append(fmt.Errorf("Provider installation was canceled by an interrupt signal."))

0 commit comments

Comments
 (0)