2023-05-02 10:33:06 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-04-13 20:05:58 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-08-09 09:34:11 -05:00
|
|
|
"fmt"
|
2017-04-13 20:05:58 -05:00
|
|
|
"log"
|
|
|
|
"path/filepath"
|
2017-08-09 09:34:11 -05:00
|
|
|
"runtime"
|
2020-01-13 15:50:05 -06:00
|
|
|
|
2021-05-17 14:07:38 -05:00
|
|
|
"github.com/hashicorp/terraform/internal/command/cliconfig"
|
2017-04-13 20:05:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// globalPluginDirs returns directories that should be searched for
|
|
|
|
// globally-installed plugins (not specific to the current configuration).
|
|
|
|
//
|
|
|
|
// Earlier entries in this slice get priority over later when multiple copies
|
|
|
|
// of the same plugin version are found, but newer versions always override
|
|
|
|
// older versions where both satisfy the provider version constraints.
|
|
|
|
func globalPluginDirs() []string {
|
|
|
|
var ret []string
|
|
|
|
// Look in ~/.terraform.d/plugins/ , or its equivalent on non-UNIX
|
2020-01-13 15:50:05 -06:00
|
|
|
dir, err := cliconfig.ConfigDir()
|
2017-04-13 20:05:58 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("[ERROR] Error finding global config directory: %s", err)
|
|
|
|
} else {
|
2017-08-09 09:34:11 -05:00
|
|
|
machineDir := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
|
2017-08-09 16:46:49 -05:00
|
|
|
ret = append(ret, filepath.Join(dir, "plugins"))
|
2017-08-09 09:34:11 -05:00
|
|
|
ret = append(ret, filepath.Join(dir, "plugins", machineDir))
|
2017-04-13 20:05:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|