From 7b96a9fa0673e845684c5eac8df6330083347de7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Sep 2014 20:43:59 -0700 Subject: [PATCH] command: expand ~ manually in var-file [GH-273] --- CHANGELOG.md | 1 + command/flag_var.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b59f4bb9..db03ab0bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ BUG FIXES: * core: Fix certain syntax of configuration that could cause hang. [GH-261] * core: `-no-color` flag properly disables color. [GH-250] + * core: "~" is expanded in `-var-file` flags. [GH-273] * providers/aws: Refreshing EIP from pre-0.2 state file won't error. [GH-258] * providers/google: Attaching a disk source (not an image) works properly. [GH-254] diff --git a/command/flag_var.go b/command/flag_var.go index 62f8066c0..81e6e7884 100644 --- a/command/flag_var.go +++ b/command/flag_var.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/hashicorp/hcl" + "github.com/mitchellh/go-homedir" ) // FlagVar is a flag.Value implementation for parsing user variables @@ -56,7 +57,13 @@ func (v *FlagVarFile) Set(raw string) error { return nil } -func loadVarFile(path string) (map[string]string, error) { +func loadVarFile(rawPath string) (map[string]string, error) { + path, err := homedir.Expand(rawPath) + if err != nil { + return nil, fmt.Errorf( + "Error expanding path: %s", err) + } + // Read the HCL file and prepare for parsing d, err := ioutil.ReadFile(path) if err != nil {