github.com/hashicorp/packer@v1.14.3/packer/plugin_folders.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package packer
     5  
     6  import (
     7  	"fmt"
     8  	"log"
     9  	"os"
    10  	"path/filepath"
    11  	"strings"
    12  
    13  	"github.com/hashicorp/packer-plugin-sdk/pathing"
    14  )
    15  
    16  var pathSep = fmt.Sprintf("%c", os.PathListSeparator)
    17  
    18  // PluginFolder returns the known plugin folder based on system.
    19  func PluginFolder() (string, error) {
    20  	if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
    21  		if strings.Contains(packerPluginPath, pathSep) {
    22  			return "", fmt.Errorf("Multiple paths are no longer supported for PACKER_PLUGIN_PATH.\n"+
    23  				"This should be defined as one of the following options for your environment:"+
    24  				"\n* PACKER_PLUGIN_PATH=%v", strings.Join(strings.Split(packerPluginPath, pathSep), "\n* PACKER_PLUGIN_PATH="))
    25  		}
    26  
    27  		return packerPluginPath, nil
    28  	}
    29  
    30  	cd, err := pathing.ConfigDir()
    31  	if err != nil {
    32  		log.Printf("[ERR] Error loading config directory: %v", err)
    33  		return "", err
    34  	}
    35  
    36  	return filepath.Join(cd, "plugins"), nil
    37  }