mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
ffe056bacb
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
// +build !windows
|
|
|
|
package cliconfig
|
|
|
|
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 set up. 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
|
|
}
|