config: interprets '~' as the current user home dir in file()

This commit is contained in:
7heo 2015-03-31 01:52:39 +02:00
parent 19d6fdfc34
commit a6411626bf
1 changed files with 7 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import (
"strings"
"github.com/hashicorp/terraform/config/lang/ast"
"github.com/mitchellh/go-homedir"
)
// Funcs is the mapping of built-in functions for configuration.
@ -57,7 +58,12 @@ func interpolationFuncFile() ast.Function {
ArgTypes: []ast.Type{ast.TypeString},
ReturnType: ast.TypeString,
Callback: func(args []interface{}) (interface{}, error) {
data, err := ioutil.ReadFile(args[0].(string))
var path string
path, err := homedir.Expand(args[0].(string))
if err != nil {
return "", err
}
data, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}