Skip to content

Commit

Permalink
config looks in a plugin directory if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Sep 27, 2014
1 parent 462f37e commit 2e39b8e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
16 changes: 16 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func configFile() (string, error) {
dir, err := configDir()
dir, err := homeDir()
if err != nil {
return "", err
}
Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
const CSIDL_APPDATA = 26

func configFile() (string, error) {
dir, err := configDir()
dir, err := homeDir()
if err != nil {
return "", err
}
Expand All @@ -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
Expand Down

0 comments on commit 2e39b8e

Please sign in to comment.