packer-cn/packer/plugin_folders.go
Adrien Delorme ed091163be
HCL2 Parse packer.required_plugins block + packer init (#10304)
This adds the new `required_plugins` block to be nested under the packer block.

Example:
```hcl
packer {
  required_plugins {
    aws = {
      version = ">= 2.7.0"
      source = "azr/aws"
    }
    azure = ">= 2.7.0"
  }
}
```

For example on darwin_amd64 Packer will install those under :
* "${PACKER_HOME_DIR}/plugin/github.com/azr/amazon/packer-plugin-amazon_2.7.0_x5.0_darwin_amd64"
* "${PACKER_HOME_DIR}/plugin/github.com/hashicorp/azure/packer-plugin-azure_2.7.0_x5.0_darwin_amd64_x5"

+ docs
+ tests
2021-02-02 18:05:04 +01:00

36 lines
794 B
Go

package packer
import (
"log"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/packer-plugin-sdk/pathing"
)
// PluginFolders returns the list of known plugin folders based on system.
func PluginFolders(dirs ...string) []string {
res := []string{}
if path, err := os.Executable(); err != nil {
log.Printf("[ERR] Error finding executable: %v", err)
} else {
res = append(res, path)
}
res = append(res, dirs...)
if cd, err := pathing.ConfigDir(); err != nil {
log.Printf("[ERR] Error loading config directory: %v", err)
} else {
res = append(res, filepath.Join(cd, "plugins"))
}
if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
res = append(res, strings.Split(packerPluginPath, string(os.PathListSeparator))...)
}
return res
}