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