packer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 38

Documentation

Overview

Package packer allows to interact with Packer.

Index

Constants

This section is empty.

Variables

View Source
var ErrArtifactIDNotFound = errors.New("could not find artifact ID pattern in packer output")

ErrArtifactIDNotFound is returned when the Packer output does not contain an artifact ID.

Functions

func BuildAmi deprecated

func BuildAmi(t testing.TestingT, options *Options) string

BuildAmi builds the given Packer template and return the generated AMI ID.

Deprecated: Use BuildArtifactContext instead.

func BuildAmiE deprecated

func BuildAmiE(t testing.TestingT, options *Options) (string, error)

BuildAmiE builds the given Packer template and return the generated AMI ID.

Deprecated: Use BuildArtifactContextE instead.

func BuildArtifact deprecated added in v0.10.0

func BuildArtifact(t testing.TestingT, options *Options) string

BuildArtifact builds the given Packer template and return the generated Artifact ID.

Deprecated: Use BuildArtifactContext instead.

func BuildArtifactContext added in v1.0.0

func BuildArtifactContext(t testing.TestingT, ctx context.Context, options *Options) string

BuildArtifactContext builds the given Packer template and return the generated Artifact ID. This function will fail the test if there is an error. The ctx parameter supports cancellation and timeouts.

func BuildArtifactContextE added in v1.0.0

func BuildArtifactContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)

BuildArtifactContextE builds the given Packer template and return the generated Artifact ID. The ctx parameter supports cancellation and timeouts.

func BuildArtifactE deprecated added in v0.10.0

func BuildArtifactE(t testing.TestingT, options *Options) (string, error)

BuildArtifactE builds the given Packer template and return the generated Artifact ID.

Deprecated: Use BuildArtifactContextE instead.

func BuildArtifacts deprecated added in v0.13.9

func BuildArtifacts(t testing.TestingT, artifactNameToOptions map[string]*Options) map[string]string

BuildArtifacts can take a map of identifierName <-> Options and then parallelize the packer builds. Once all the packer builds have completed a map of identifierName <-> generated identifier is returned. The identifierName can be anything you want, it is only used so that you can know which generated artifact is which.

Deprecated: Use BuildArtifactsContext instead.

func BuildArtifactsContext added in v1.0.0

func BuildArtifactsContext(t testing.TestingT, ctx context.Context, artifactNameToOptions map[string]*Options) map[string]string

BuildArtifactsContext can take a map of identifierName <-> Options and then parallelize the packer builds. Once all the packer builds have completed a map of identifierName <-> generated identifier is returned. The identifierName can be anything you want, it is only used so that you can know which generated artifact is which. This function will fail the test if there is an error. The ctx parameter supports cancellation and timeouts.

func BuildArtifactsContextE added in v1.0.0

func BuildArtifactsContextE(t testing.TestingT, ctx context.Context, artifactNameToOptions map[string]*Options) (map[string]string, error)

BuildArtifactsContextE can take a map of identifierName <-> Options and then parallelize the packer builds. Once all the packer builds have completed a map of identifierName <-> generated identifier is returned. If any artifact fails to build, the errors are accumulated and returned as a MultiError. The identifierName can be anything you want, it is only used so that you can know which generated artifact is which. The ctx parameter supports cancellation and timeouts.

func BuildArtifactsE deprecated added in v0.13.9

func BuildArtifactsE(t testing.TestingT, artifactNameToOptions map[string]*Options) (map[string]string, error)

BuildArtifactsE can take a map of identifierName <-> Options and then parallelize the packer builds. Once all the packer builds have completed a map of identifierName <-> generated identifier is returned. If any artifact fails to build, the errors are accumulated and returned as a MultiError. The identifierName can be anything you want, it is only used so that you can know which generated artifact is which.

Deprecated: Use BuildArtifactsContextE instead.

func ExtractArtifactID added in v1.0.0

func ExtractArtifactID(packerLogOutput string) (string, error)

ExtractArtifactID extracts the artifact ID from Packer machine-readable log output.

The Packer machine-readable log output should contain an entry of this format:

AWS: <timestamp>,<builder>,artifact,<index>,id,<region>:<image_id> GCP: <timestamp>,<builder>,artifact,<index>,id,<image_id>

For example:

1456332887,amazon-ebs,artifact,0,id,us-east-1:ami-b481b3de 1533742764,googlecompute,artifact,0,id,terratest-packer-example-2018-08-08t15-35-19z

func FormatPackerArgs added in v1.0.0

func FormatPackerArgs(options *Options) []string

FormatPackerArgs converts the inputs to a format palatable to packer. The build command should have the format:

packer build [OPTIONS] template

func GetArtifactIDFromManifestBuildName deprecated added in v0.49.0

func GetArtifactIDFromManifestBuildName(t testing.TestingT, manifestPath string, buildName string) string

GetArtifactIDFromManifestBuildName returns the artifact id from a build name contained in the manifest file. See https://developer.hashicorp.com/packer/docs/post-processors/manifest for more info. If the build name is not found, it will fail the test.

Deprecated: Use GetArtifactIDFromManifestBuildNameContext instead.

func GetArtifactIDFromManifestBuildNameContext added in v1.0.0

func GetArtifactIDFromManifestBuildNameContext(t testing.TestingT, ctx context.Context, manifestPath string, buildName string) string

GetArtifactIDFromManifestBuildNameContext returns the artifact id from a build name contained in the manifest file. See https://developer.hashicorp.com/packer/docs/post-processors/manifest for more info. This function will fail the test if there is an error. The ctx parameter is accepted for API consistency with other Context functions.

func GetArtifactIDFromManifestBuildNameContextE added in v1.0.0

func GetArtifactIDFromManifestBuildNameContextE(t testing.TestingT, ctx context.Context, manifestPath string, buildName string) (string, error)

GetArtifactIDFromManifestBuildNameContextE returns the artifact id from a build name contained in the manifest file. See https://developer.hashicorp.com/packer/docs/post-processors/manifest for more info. The ctx parameter is accepted for API consistency with other Context functions.

func GetArtifactIDFromManifestBuildNameE deprecated added in v0.49.0

func GetArtifactIDFromManifestBuildNameE(t testing.TestingT, manifestPath string, buildName string) (string, error)

GetArtifactIDFromManifestBuildNameE returns the artifact id from a build name contained in the manifest file. See https://developer.hashicorp.com/packer/docs/post-processors/manifest for more info.

Deprecated: Use GetArtifactIDFromManifestBuildNameContextE instead.

func TrimPackerVersion added in v1.0.0

func TrimPackerVersion(versionCmdOutput string) string

TrimPackerVersion extracts the version number from packer version output. From packer 1.10 the -version command output is prefixed with "Packer v".

Types

type BuildNameNotFoundError added in v1.0.0

type BuildNameNotFoundError struct {
	BuildName    string
	ManifestPath string
}

BuildNameNotFoundError is returned when the specified build name is not found in the manifest file.

func (*BuildNameNotFoundError) Error added in v1.0.0

func (e *BuildNameNotFoundError) Error() string

Error implements the error interface for BuildNameNotFoundError.

type Options

type Options struct {
	Vars                       map[string]string // The custom vars to pass when running the build command
	Env                        map[string]string // Custom environment variables to set when running Packer
	RetryableErrors            map[string]string // If packer build fails with one of these (transient) errors, retry. The keys are a regexp to match against the error and the message is what to display to a user if that error is matched.
	Logger                     *logger.Logger    // If set, use a non-default logger
	Template                   string            // The path to the Packer template
	Only                       string            // If specified, only run the build of this name
	Except                     string            // Runs the build excluding the specified builds and post-processors
	WorkingDir                 string            // The directory to run packer in
	VarFiles                   []string          // Var file paths to pass Packer using -var-file option
	TimeBetweenRetries         time.Duration     // The amount of time to wait between retries
	MaxRetries                 int               // Maximum number of times to retry errors matching RetryableErrors
	DisableTemporaryPluginPath bool              // If set, do not use a temporary directory for Packer plugins.
}

Options are the options for Packer.

Jump to

Keyboard shortcuts

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