v0.5.4 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2024 License: MPL-2.0 Imports: 1 Imported by: 180



Package common provides the PackerConfig structure that gets passed to every plugin and contains information populated by the Packer core. This config contains data about command line flags that were used, as well as template information and information about the Packer core's version. It also proivdes string constants to use to access that config.



View Source
const (
	// This is the key in configurations that is set to the name of the
	// build.
	BuildNameConfigKey = "packer_build_name"

	// This is the key in the configuration that is set to the type
	// of the builder that is run. This is useful for provisioners and
	// such who want to make use of this.
	BuilderTypeConfigKey = "packer_builder_type"

	// this is the key in the configuration that is set to the version of the
	// Packer Core. This can be used by plugins to set user agents, etc, without
	// having to import the Core to find out the Packer version.
	CoreVersionConfigKey = "packer_core_version"

	// This is the key in configurations that is set to "true" when Packer
	// debugging is enabled.
	DebugConfigKey = "packer_debug"

	// This is the key in configurations that is set to "true" when Packer
	// force build is enabled.
	ForceConfigKey = "packer_force"

	// This key determines what to do when a normal multistep step fails
	// - "cleanup" - run cleanup steps
	// - "abort" - exit without cleanup
	// - "ask" - ask the user
	OnErrorConfigKey = "packer_on_error"

	// TemplatePathKey is the path to the template that configured this build
	TemplatePathKey = "packer_template_path"

	// This key contains a map[string]string of the user variables for
	// template processing.
	UserVariablesConfigKey = "packer_user_variables"


This section is empty.


func ShellCommand

func ShellCommand(command string) *exec.Cmd

ShellCommand takes a command string and returns an *exec.Cmd to execute it within the context of a shell (/bin/sh).


type CommandWrapper

type CommandWrapper func(string) (string, error)

CommandWrapper is a type that given a command, will modify that command in-flight. This might return an error. For example, your command could be `foo` and your CommandWrapper could be

func(s string) (string, error) {
	 return fmt.Sprintf("/bin/sh/ %s", s)

Using the CommandWrapper, you can set environment variables or perform string interpolation once rather than many times, to save some lines of code if similar wrapping needs to be performed many times during a plugin run.

type PackerConfig

type PackerConfig struct {
	PackerBuildName     string            `mapstructure:"packer_build_name"`
	PackerBuilderType   string            `mapstructure:"packer_builder_type"`
	PackerCoreVersion   string            `mapstructure:"packer_core_version"`
	PackerDebug         bool              `mapstructure:"packer_debug"`
	PackerForce         bool              `mapstructure:"packer_force"`
	PackerOnError       string            `mapstructure:"packer_on_error"`
	PackerUserVars      map[string]string `mapstructure:"packer_user_variables"`
	PackerSensitiveVars []string          `mapstructure:"packer_sensitive_variables"`

PackerConfig is a struct that contains the configuration keys that are sent by packer, properly tagged already so mapstructure can load them. Embed this structure into your configuration class to get access to this information from the Packer Core.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL