config looks in a plugin directory if it exists
This commit is contained in:
parent
462f37e2b7
commit
2e39b8eaf3
16
config.go
16
config.go
|
@ -41,6 +41,11 @@ func ConfigFile() (string, error) {
|
|||
return configFile()
|
||||
}
|
||||
|
||||
// ConfigDir returns the configuration directory for Terraform.
|
||||
func ConfigDir() (string, error) {
|
||||
return configDir()
|
||||
}
|
||||
|
||||
// LoadConfig loads the CLI configuration from ".terraformrc" files.
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
// Read the HCL file and prepare for parsing
|
||||
|
@ -76,6 +81,17 @@ func (c *Config) Discover() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Look in the plugins directory. This will override any found
|
||||
// in the current directory.
|
||||
dir, err := ConfigDir()
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Error loading config directory: %s", err)
|
||||
} else {
|
||||
if err := c.discover(filepath.Join(dir, "plugins")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Next, look in the same directory as the executable. Any conflicts
|
||||
// will overwrite those found in our current directory.
|
||||
exePath, err := osext.Executable()
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func configFile() (string, error) {
|
||||
dir, err := configDir()
|
||||
dir, err := homeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -22,6 +22,15 @@ func configFile() (string, error) {
|
|||
}
|
||||
|
||||
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 != "" {
|
||||
log.Printf("Detected home directory from env var: %s", home)
|
||||
|
|
|
@ -16,7 +16,7 @@ var (
|
|||
const CSIDL_APPDATA = 26
|
||||
|
||||
func configFile() (string, error) {
|
||||
dir, err := configDir()
|
||||
dir, err := homeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -25,6 +25,15 @@ func configFile() (string, error) {
|
|||
}
|
||||
|
||||
func configDir() (string, error) {
|
||||
dir, err := homeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return filepath.Join(dir, "terraform.d"), nil
|
||||
}
|
||||
|
||||
func homeDir() (string, error) {
|
||||
b := make([]uint16, syscall.MAX_PATH)
|
||||
|
||||
// See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181(v=vs.85).aspx
|
||||
|
|
Loading…
Reference in New Issue