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