forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_unix.go
52 lines (41 loc) · 1 KB
/
config_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// +build !windows
package main
import (
"errors"
"os"
"os/user"
"path/filepath"
)
func configFile() (string, error) {
dir, err := homeDir()
if err != nil {
return "", err
}
return filepath.Join(dir, ".terraformrc"), nil
}
func configDir() (string, error) {
dir, err := homeDir()
if err != nil {
return "", err
}
return filepath.Join(dir, ".terraform.d"), nil
}
func homeDir() (string, error) {
// First prefer the HOME environmental variable
if home := os.Getenv("HOME"); home != "" {
// FIXME: homeDir gets called from globalPluginDirs during init, before
// the logging is setup. We should move meta initializtion outside of
// init, but in the meantime we just need to silence this output.
//log.Printf("[DEBUG] Detected home directory from env var: %s", home)
return home, nil
}
// If that fails, try build-in module
user, err := user.Current()
if err != nil {
return "", err
}
if user.HomeDir == "" {
return "", errors.New("blank output")
}
return user.HomeDir, nil
}