diff --git a/packer/config_file.go b/packer/config_file.go index 04275f457..173766afa 100644 --- a/packer/config_file.go +++ b/packer/config_file.go @@ -52,18 +52,31 @@ func homeDir() (string, error) { } func configFile() (string, error) { - dir, err := homeDir() - if err != nil { - return "", err + var dir string + if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" { + log.Printf("Detected config directory from env var: %s", cd) + dir = cd + } else { + homedir, err := homeDir() + if err != nil { + return "", err + } + dir = homedir } - return filepath.Join(dir, defaultConfigFile), nil } func configDir() (string, error) { - dir, err := homeDir() - if err != nil { - return "", err + var dir string + if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" { + log.Printf("Detected config directory from env var: %s", cd) + dir = cd + } else { + homedir, err := homeDir() + if err != nil { + return "", err + } + dir = homedir } return filepath.Join(dir, defaultConfigDir), nil