Files
Packer-Cn/packer/plugin_folders.go
Lucas Bajolet f80ba2821b packer: error multiple paths in PACKER_PLUGIN_PATH
When a user defines PACKER_PLUGIN_PATH in their environment, we need to
error if their path defines multiple directories separated by `:`.

This used to be supported, but this is removed with 1.11 as we're
simplifying the loading process for plugins, so we opted to fall-back to
only one plugin directory supported.
2024-05-10 15:11:41 -04:00

36 lines
956 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package packer
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/packer-plugin-sdk/pathing"
)
// PluginFolder returns the known plugin folder based on system.
func PluginFolder() (string, error) {
if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
if strings.ContainsRune(packerPluginPath, os.PathListSeparator) {
return "", fmt.Errorf("Multiple paths are no longer supported for PACKER_PLUGIN_PATH.\n"+
"This should be defined as one of the following options for your environment:"+
"\n* PACKER_PLUGIN_PATH=%v", strings.Join(strings.Split(packerPluginPath, ":"), "\n* PACKER_PLUGIN_PATH="))
}
return packerPluginPath, nil
}
cd, err := pathing.ConfigDir()
if err != nil {
log.Printf("[ERR] Error loading config directory: %v", err)
return "", err
}
return filepath.Join(cd, "plugins"), nil
}