diff --git a/hcl2template/plugin.go b/hcl2template/plugin.go index 6a66aa610..f03e03292 100644 --- a/hcl2template/plugin.go +++ b/hcl2template/plugin.go @@ -76,6 +76,7 @@ func (cfg *PackerConfig) DetectPluginBinaries() hcl.Diagnostics { Checksummers: []plugingetter.Checksummer{ {Type: "sha256", Hash: sha256.New()}, }, + ReleasesOnly: cfg.parser.PluginConfig.ReleasesOnly, }, } diff --git a/packer/plugin-getter/plugins.go b/packer/plugin-getter/plugins.go index fae1809e0..3271a868d 100644 --- a/packer/plugin-getter/plugins.go +++ b/packer/plugin-getter/plugins.go @@ -60,6 +60,10 @@ type BinaryInstallationOptions struct { Ext string Checksummers []Checksummer + + // ReleasesOnly may be set by commands like validate or build, and + // forces Packer to not consider plugin pre-releases. + ReleasesOnly bool } type ListInstallationsOptions struct { @@ -154,13 +158,18 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL // versionsStr now looks like v1.2.3_x5.1 or amazon_v1.2.3_x5.1 parts := strings.SplitN(versionsStr, "_", 2) pluginVersionStr, protocolVerionStr := parts[0], parts[1] - _, err = version.NewVersion(pluginVersionStr) + ver, err := version.NewVersion(pluginVersionStr) if err != nil { // could not be parsed, ignoring the file log.Printf("found %q with an incorrect %q version, ignoring it. %v", path, pluginVersionStr, err) continue } + if ver.Prerelease() != "" && opts.ReleasesOnly { + log.Printf("ignoring pre-release plugin %q", path) + continue + } + matches := pluginVersionRegex.FindStringSubmatch(pluginVersionStr) if matches == nil { log.Printf("invalid version found: %q, ignoring", pluginVersionStr) diff --git a/packer/plugin.go b/packer/plugin.go index c6d4c1259..d2bf0e200 100644 --- a/packer/plugin.go +++ b/packer/plugin.go @@ -34,6 +34,7 @@ type PluginConfig struct { Provisioners ProvisionerSet PostProcessors PostProcessorSet DataSources DatasourceSet + ReleasesOnly bool } // PACKERSPACE is used to represent the spaces that separate args for a command @@ -81,6 +82,7 @@ func (c *PluginConfig) Discover() error { Checksummers: []plugingetter.Checksummer{ {Type: "sha256", Hash: sha256.New()}, }, + ReleasesOnly: c.ReleasesOnly, }, }) if err != nil {