lib

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 29 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultMirror = "https://releases.hashicorp.com/terraform"
	DefaultLatest = ""
	InstallDir    = ".terraform.versions"

	DefaultProductId = "terraform"
)

Variables

Functions

func ChangeProductSymlink(product Product, binVersionPath string, userBinPath string) error

ChangeProductSymlink : move symlink for product to existing binary

func ChangeSymlink(binVersionPath string, binPath string)

ChangeSymlink : move symlink to existing binary for Terraform

Deprecated: This function has been deprecated in favor of ChangeProductSymlink and will be removed in v2.0.0

func CheckDirExist added in v1.1.0

func CheckDirExist(dir string) bool

CheckDirExist : check if directory exist dir=path to file return bool

func CheckDirHasTGBin added in v1.1.0

func CheckDirHasTGBin(dir, prefix string) bool

CheckDirHasTGBin : // check binary exist (TODO UNIT TEST)

func CheckDirWritable added in v1.1.0

func CheckDirWritable(dir string) bool

Check if user has permission to directory : dir=path to file return bool

func CheckFileExist

func CheckFileExist(file string) bool

CheckFileExist : check if file exist in directory

func CheckSymlink(symlinkPath string) bool

CheckSymlink : check file is symlink

func ConvertExecutableExt added in v1.1.0

func ConvertExecutableExt(fpath string) string

ConvertExecutableExt : convert executable with local OS extension

func CreateSymlink(cwd string, dir string) error

CreateSymlink : create symlink or copy file to bin directory if windows

func DownloadFromURL

func DownloadFromURL(installLocation, mirrorURL, tfversion, versionPrefix, goos, goarch string) (string, error)

DownloadFromURL : Downloads the terraform binary and its hash from the source url

func DownloadProductFromURL added in v1.2.0

func DownloadProductFromURL(product Product, installLocation, mirrorURL, tfversion, versionPrefix, goos, goarch string) (string, error)

func FileExistsAndIsNotDir added in v1.1.0

func FileExistsAndIsNotDir(filename string) bool

FileExistsAndIsNotDir checks if a file exists and is not a directory before we try using it to prevent further errors

func GetCurrentDirectory added in v1.1.0

func GetCurrentDirectory() string

GetCurrentDirectory : return the current directory

func GetFileName added in v1.1.0

func GetFileName(configfile string) string

GetFileName : remove file ext. .tfswitch.config returns .tfswitch

func GetHomeDirectory added in v1.1.0

func GetHomeDirectory() string

GetHomeDirectory : return the user's home directory

func GetInstallLocation added in v1.2.0

func GetInstallLocation(installPath string) string

GetInstallLocation : get location where the terraform binary will be installed, will create the installDir if it does not exist

func GetSemver added in v1.1.0

func GetSemver(tfconstraint string, mirrorURL string) (string, error)

GetSemver : returns version that will be installed based on server constraint provided

func InitLogger added in v1.1.0

func InitLogger(logLevel string) *slog.Logger

func InstallLatestImplicitVersion deprecated added in v1.1.0

func InstallLatestImplicitVersion(dryRun bool, requestedVersion, customBinaryPath, installPath, mirrorURL, arch string, preRelease bool)

InstallLatestImplicitVersion install latest - argument (version) must be provided

Deprecated: This function has been deprecated in favor of InstallLatestProductImplicitVersion and will be removed in v2.0.0

func InstallLatestProductImplicitVersion added in v1.2.0

func InstallLatestProductImplicitVersion(product Product, dryRun bool, requestedVersion, customBinaryPath, installPath, mirrorURL, arch string, preRelease bool) error

InstallLatestProductImplicitVersion install latest - argument (version) must be provided

func InstallLatestProductVersion added in v1.2.0

func InstallLatestProductVersion(product Product, dryRun bool, customBinaryPath, installPath, mirrorURL, arch string) error

InstallLatestProductVersion install latest stable tf version

func InstallLatestVersion deprecated added in v1.1.0

func InstallLatestVersion(dryRun bool, customBinaryPath, installPath, mirrorURL, arch string)

InstallLatestVersion install latest stable tf version

Deprecated: This function has been deprecated in favor of InstallLatestProductVersion and will be removed in v2.0.0

func InstallOption deprecated added in v1.1.0

func InstallOption(listAll, dryRun bool, customBinaryPath, installPath, mirrorURL, arch string)

InstallProductOption displays & installs tf version listAll = true - all versions including beta and rc will be displayed */ listAll = false - only official stable release are displayed */

Deprecated: This function has been deprecated in favor of InstallProductOption and will be removed in v2.0.0

func InstallProductOption added in v1.2.0

func InstallProductOption(product Product, listAll, dryRun bool, customBinaryPath, installPath, mirrorURL, arch string) error

InstallProductOption displays & installs tf version

listAll = true - all versions including beta and rc will be displayed
listAll = false - only official stable release are displayed

func InstallProductVersion added in v1.2.0

func InstallProductVersion(product Product, dryRun bool, version, customBinaryPath, installPath, mirrorURL, arch string) error

InstallProductVersion install with provided version as argument

func InstallVersion deprecated added in v1.1.0

func InstallVersion(dryRun bool, version, customBinaryPath, installPath, mirrorURL, arch string)

InstallVersion install Terraform product

Deprecated: This function has been deprecated in favor of InstallProductVersion and will be removed in v2.0.0

func IsDirEmpty added in v1.1.0

func IsDirEmpty(dir string) bool

IsDirEmpty : check if directory is empty (TODO UNIT TEST)

func NewStderrConsoleHandler added in v1.2.3

func NewStderrConsoleHandler(levels []slog.Level) *handler.ConsoleHandler

func NewStderrConsoleWithLF added in v1.2.3

func NewStderrConsoleWithLF(lf slog.LevelFormattable) *handler.ConsoleHandler

func Path added in v1.1.0

func Path(value string) string

Path : returns path of directory value=path to file

func PrintInvalidMinorTFVersion added in v1.1.0

func PrintInvalidMinorTFVersion()

PrintInvalidMinorTFVersion Print invalid minor TF version

func PrintInvalidTFVersion added in v1.1.0

func PrintInvalidTFVersion()

PrintInvalidTFVersion Print invalid TF version

func ReadLines deprecated added in v1.1.0

func ReadLines(path string) (lines []string, err error)

ReadLines : Read a whole file into the memory and store it as array of lines

Deprecated: This method has been deprecated and will be removed in v2.0.0

func RemoveFiles

func RemoveFiles(src string)

RemoveFiles : remove file

func RemoveSymlink(symlinkPath string) error

RemoveSymlink : remove symlink

func RenameFile

func RenameFile(src string, dest string)

RenameFile : rename file name

func SemVerParser added in v1.1.0

func SemVerParser(tfconstraint *string, tflist []string) (string, error)

SemVerParser : Goes through the list of terraform version, return a valid tf version for contraint provided

func ShowLatestImplicitVersion added in v1.1.0

func ShowLatestImplicitVersion(requestedVersion, mirrorURL string, preRelease bool)

ShowLatestImplicitVersion show latest - argument (version) must be provided

func ShowLatestVersion added in v1.1.0

func ShowLatestVersion(mirrorURL string)

ShowLatestVersion show install latest stable tf version

func Unzip

func Unzip(src string, dest string, fileToUnzipSlice ...string) ([]string, error)

Unzip will decompress a zip archive, moving all files and folders within the zip file (parameter 1) to an output directory (parameter 2). fileToUnzip (parameter 3) specifies the file within the zipfile to be extracted. This is optional and default to "terraform"

func UsageMessage added in v1.1.0

func UsageMessage()

func WriteLines deprecated added in v1.1.0

func WriteLines(lines []string, path string) (err error)

WriteLines : writes into file

Deprecated: This method has been deprecated and will be removed in v2.0.0

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command : type string

func NewCommand

func NewCommand(name string) *Command

NewCommand : get command

func (*Command) Find

func (cmd *Command) Find() func() string

Find : find all bin path

func (*Command) PathList

func (cmd *Command) PathList() []string

PathList : get bin path list

type OpenTofuProduct added in v1.2.0

type OpenTofuProduct struct {
	ProductDetails
}

func (OpenTofuProduct) GetArchivePrefix added in v1.2.0

func (p OpenTofuProduct) GetArchivePrefix() string

func (OpenTofuProduct) GetArtifactUrl added in v1.2.0

func (p OpenTofuProduct) GetArtifactUrl(mirrorURL string, version string) string

func (OpenTofuProduct) GetDefaultMirrorUrl added in v1.2.0

func (p OpenTofuProduct) GetDefaultMirrorUrl() string

func (OpenTofuProduct) GetExecutableName added in v1.2.0

func (p OpenTofuProduct) GetExecutableName() string

func (OpenTofuProduct) GetId added in v1.2.0

func (p OpenTofuProduct) GetId() string

OpenTofu methods

func (OpenTofuProduct) GetName added in v1.2.0

func (p OpenTofuProduct) GetName() string

func (OpenTofuProduct) GetPublicKeyId added in v1.2.0

func (p OpenTofuProduct) GetPublicKeyId() string

func (OpenTofuProduct) GetPublicKeyUrl added in v1.2.0

func (p OpenTofuProduct) GetPublicKeyUrl() string

func (OpenTofuProduct) GetRecentVersionProduct added in v1.2.0

func (p OpenTofuProduct) GetRecentVersionProduct(recentFile *RecentFile) []string

func (OpenTofuProduct) GetShaSignatureSuffix added in v1.2.0

func (p OpenTofuProduct) GetShaSignatureSuffix() string

func (OpenTofuProduct) GetVersionPrefix added in v1.2.0

func (p OpenTofuProduct) GetVersionPrefix() string

func (OpenTofuProduct) SetRecentVersionProduct added in v1.2.0

func (p OpenTofuProduct) SetRecentVersionProduct(recentFile *RecentFile, versions []string)

type Product added in v1.2.0

type Product interface {
	GetId() string
	GetName() string
	GetDefaultMirrorUrl() string
	GetVersionPrefix() string
	GetExecutableName() string
	GetArchivePrefix() string
	GetPublicKeyId() string
	GetPublicKeyUrl() string
	GetShaSignatureSuffix() string
	GetArtifactUrl(mirrorURL string, version string) string
	GetRecentVersionProduct(recentFile *RecentFile) []string
	SetRecentVersionProduct(recentFile *RecentFile, versions []string)
}

func GetAllProducts added in v1.2.0

func GetAllProducts() []Product

func GetProductById added in v1.2.0

func GetProductById(id string) Product

type ProductDetails added in v1.2.0

type ProductDetails struct {
	ID                    string
	Name                  string
	DefaultMirror         string
	VersionPrefix         string
	DefaultDownloadMirror string
	ExecutableName        string
	ArchivePrefix         string
	PublicKeyId           string
	PublicKeyUrl          string
}

type RecentFile added in v1.2.0

type RecentFile struct {
	Terraform []string `json:"terraform"`
	OpenTofu  []string `json:"opentofu"`
}

type TerraformProduct added in v1.2.0

type TerraformProduct struct {
	ProductDetails
}

func (TerraformProduct) GetArchivePrefix added in v1.2.0

func (p TerraformProduct) GetArchivePrefix() string

func (TerraformProduct) GetArtifactUrl added in v1.2.0

func (p TerraformProduct) GetArtifactUrl(mirrorURL string, version string) string

func (TerraformProduct) GetDefaultMirrorUrl added in v1.2.0

func (p TerraformProduct) GetDefaultMirrorUrl() string

func (TerraformProduct) GetExecutableName added in v1.2.0

func (p TerraformProduct) GetExecutableName() string

func (TerraformProduct) GetId added in v1.2.0

func (p TerraformProduct) GetId() string

Terraform Product

func (TerraformProduct) GetName added in v1.2.0

func (p TerraformProduct) GetName() string

func (TerraformProduct) GetPublicKeyId added in v1.2.0

func (p TerraformProduct) GetPublicKeyId() string

func (TerraformProduct) GetPublicKeyUrl added in v1.2.0

func (p TerraformProduct) GetPublicKeyUrl() string

func (TerraformProduct) GetRecentVersionProduct added in v1.2.0

func (p TerraformProduct) GetRecentVersionProduct(recentFile *RecentFile) []string

func (TerraformProduct) GetShaSignatureSuffix added in v1.2.0

func (p TerraformProduct) GetShaSignatureSuffix() string

func (TerraformProduct) GetVersionPrefix added in v1.2.0

func (p TerraformProduct) GetVersionPrefix() string

func (TerraformProduct) SetRecentVersionProduct added in v1.2.0

func (p TerraformProduct) SetRecentVersionProduct(recentFile *RecentFile, versions []string)

type VersionSelector added in v1.2.0

type VersionSelector struct {
	Version string
	Label   string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL