From bc697e0ce7e1b9134c2d479c682fe190b1b13285 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Sun, 13 Feb 2022 22:48:19 -0500 Subject: [PATCH] Add constants for legacy mode values --- command/build.go | 10 +++++----- command/meta.go | 13 +++++++++++++ command/vendored_plugins.go | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/command/build.go b/command/build.go index d60c921b5..e0ffcd4fd 100644 --- a/command/build.go +++ b/command/build.go @@ -113,7 +113,7 @@ func (m *Meta) GetConfig(cla *MetaArgs) (packer.Handler, int) { // This is an internal-only method that should be called by commands that don't have // a different mode when handling legacy JSON templates; mainly build, validate. func DisplayLegacyConfigWarning(ui packersdk.Ui) { - if v := os.Getenv("PACKER_LEGACY_MODE"); strings.ToLower(v) == "on" { + if v := os.Getenv(PackerLegacyModeEnv); strings.ToUpper(v) == packerLegacyModeOn { return } @@ -130,11 +130,11 @@ templates will continue to work but users are encouraged to move to HCL style te See: https://learn.hashicorp.com/tutorials/packer/hcl2-upgrade `) - coloredUi.Say(`In JSON mode automatic loading of vendored plugins is enabled by default. In future -this feature will be removed and Packer will rely only on system installed plugins. -To disable automatic loading of vendored plugins set PACKER_LEGACY_MODE=off + coloredUi.Say(fmt.Sprintf(`In JSON mode automatic loading of vendored plugins is enabled by default. In the +future this feature will be removed and Packer will rely only on system installed plugins. +To disable automatic loading of vendored plugins set %s=%s See: https://packer.io/docs/templates/legacy-mode -`) +`, PackerLegacyModeEnv, packerLegacyModeOff)) } diff --git a/command/meta.go b/command/meta.go index 53b5dabd2..08b0b5df2 100644 --- a/command/meta.go +++ b/command/meta.go @@ -23,6 +23,19 @@ const ( FlagSetVars ) +const ( + /* + PACKER_LEGACY_MODE is an environment variable used by Packer to control features consider legacy as of 1.8.0. + By default when the variable is unset Packer will display warnings to the user. + + Setting PACKER_LEGACY_MODE=OFF will display warnings to the user when running, and may disable other features. + Setting PACKER_LEGACY_MODE=ON will not display warnings, and will Packer with all legacy features enabled. + */ + PackerLegacyModeEnv string = "PACKER_LEGACY_MODE" + packerLegacyModeOn string = "ON" + packerLegacyModeOff string = "OFF" +) + // Meta contains the meta-options and functionality that nearly every // Packer command inherits. type Meta struct { diff --git a/command/vendored_plugins.go b/command/vendored_plugins.go index 7a18585ef..31891dc78 100644 --- a/command/vendored_plugins.go +++ b/command/vendored_plugins.go @@ -191,10 +191,10 @@ var VendoredPostProcessors = map[string]packersdk.PostProcessor{ // set of plugins. func init() { - // By default PACKER_LEGACY_MODE=auto to enable automatic loading of vendored plugins. + // By default PACKER_LEGACY_MODE is unset to enable automatic loading of vendored plugins. // In preparation for removing vendored plugins entirely we are providing users a flag to // to control if vendored plugins should be loaded or not. - if v := os.Getenv("PACKER_LEGACY_MODE"); strings.ToLower(v) == "off" { + if v := os.Getenv(PackerLegacyModeEnv); strings.ToUpper(v) == packerLegacyModeOff { return }