Skip to content

Commit

Permalink
init: fix --force and pre-releases installed case
Browse files Browse the repository at this point in the history
When packer init is invoked with a --force argument, but no --update, we
clamp the version to install based on the last one locally installed.

Doing this may however cause the constraint to always be false if the
latest available version of a plugin is a pre-release, as none of the
upstream constraints will match that.

Therefore this commit changes how the constraint is derived from the
local list of installations, so that only the last installation that
matches the original constraint will be used, and not a pre-release.
  • Loading branch information
lbajolet-hashicorp committed Apr 29, 2024
1 parent 4883bcc commit cd51a94
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,20 @@ for more info.`)
}

if cla.Force && !cla.Upgrade {
pluginRequirement.VersionConstraints, _ = gversion.NewConstraint(fmt.Sprintf("=%s", installs[len(installs)-1].Version))
// Only place another constaint to the latest release
// binary, if any, otherwise this is essentially the same
// as an upgrade
var installVersion string
for _, install := range installs {
ver, _ := gversion.NewVersion(install.Version)
if ver.Prerelease() == "" {
installVersion = install.Version
}
}

if installVersion != "" {
pluginRequirement.VersionConstraints, _ = gversion.NewConstraint(fmt.Sprintf("=%s", installVersion))
}
}
}

Expand Down

0 comments on commit cd51a94

Please sign in to comment.