Skip to content

Commit

Permalink
Add support for specifying env vars for the Packer build
Browse files Browse the repository at this point in the history
  • Loading branch information
brikis98 committed Apr 3, 2018
1 parent 2a312b8 commit 5515950
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@ import (
)

type PackerOptions struct {
Template string // The path to the Packer template
Template string // The path to the Packer template
Vars map[string]string // The custom vars to pass when running the build command
Only string // If specified, only run the build of this name
Env map[string]string // Custom environment variables to set when running Packer
}

// Build the given Packer template and return the generated AMI ID
func BuildAmi(options PackerOptions, logger *log.Logger) (string, error) {
logger.Printf("Running Packer to generate AMI for template %s", options.Template)

output, err := shell.RunCommandAndGetOutput(shell.Command {Command: "packer", Args: formatPackerArgs(options)}, logger)
cmd := shell.Command {
Command: "packer",
Args: formatPackerArgs(options),
Env: options.Env,
}

output, err := shell.RunCommandAndGetOutput(cmd, logger)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 5515950

Please sign in to comment.