Documentation ¶
Index ¶
- Constants
- Variables
- func AsTerraformEnvVarJsonValue(value interface{}) (string, error)
- func CanonicalPath(path string, basePath string) (string, error)
- func CanonicalPaths(paths []string, basePath string) ([]string, error)
- func CleanPath(path string) string
- func CloneStringList(listToClone []string) []string
- func CloneStringMap(mapToClone map[string]string) map[string]string
- func CommaSeparatedStrings(list []string) string
- func ContainsPath(path, subpath string) bool
- func CopyFile(source string, destination string) error
- func CopyFolderContents(source, destination, manifestFile string, includeInCopy []string) error
- func CopyFolderContentsWithFilter(source, destination, manifestFile string, ...) error
- func CopyLockFile(sourceFolder string, destinationFolder string, logger *logrus.Entry) error
- func CreateLogEntry(prefix string, level logrus.Level) *logrus.Entry
- func CreateLogEntryWithWriter(writer io.Writer, prefix string, level logrus.Level, hooks logrus.LevelHooks) *logrus.Entry
- func CreateLogger(lvl logrus.Level) *logrus.Logger
- func DisableJsonFormat()
- func DisableLogColors()
- func DoWithRetry(ctx context.Context, actionDescription string, maxRetries int, ...) error
- func EncodeBase64Sha1(str string) string
- func EnsureDirectory(path string) error
- func FetchFile(ctx context.Context, downloadURL, saveToFile string) error
- func FileExists(path string) bool
- func FileNotExists(path string) bool
- func FileOrData(maybePath string) (string, error)
- func FirstArg[S ~[]E, E comparable](args S) E
- func FolderPathAsFile(folderPath string) string
- func GenerateRandomSha256() (string, error)
- func GetCacheDir() (string, error)
- func GetDefaultLogLevel() logrus.Level
- func GetDiagnosticsWriter(logger *logrus.Entry, parser *hclparse.Parser) hcl.DiagnosticWriter
- func GetPathRelativeTo(path string, basePath string) (string, error)
- func GetRandomTime(lowerBound, upperBound time.Duration) time.Duration
- func GlobCanonicalPath(basePath string, globPaths ...string) ([]string, error)
- func Grep(regex *regexp.Regexp, glob string) (bool, error)
- func HasPathPrefix(path, prefix string) bool
- func IsCommandExecutable(command string, args ...string) bool
- func IsDir(path string) bool
- func IsDirectoryEmpty(dirPath string) (bool, error)
- func IsFile(path string) bool
- func IsSymLink(path string) bool
- func JoinPath(elem ...string) string
- func JoinTerraformModulePath(modulesFolder string, path string) string
- func JsonFormat()
- func KindOf(value interface{}) reflect.Kind
- func LastArg[S ~[]E, E comparable](args S) E
- func ListContainsElement[S ~[]E, E comparable](list S, element any) bool
- func ListContainsSublist[S ~[]E, E comparable](list, sublist S) bool
- func ListEquals[S ~[]E, E comparable](a, b S) bool
- func ListHasPrefix[S ~[]E, E comparable](list, prefix S) bool
- func ListTfFiles(directoryPath string) ([]string, error)
- func MatchesAny(regExps []string, s string) bool
- func Min(x, y int) int
- func MustWalkTerraformOutput(value interface{}, path ...string) interface{}
- func ParseLogLevel(logLevelStr string) logrus.Level
- func ParseTimestamp(ts string) (time.Time, error)
- func PrefixedWriter(writer io.Writer, prefix string) io.Writer
- func ReadFileAsString(path string) (string, error)
- func RemoveDuplicatesFromList[S ~[]E, E comparable](list S) S
- func RemoveDuplicatesFromListKeepLast[S ~[]E, E comparable](list S) S
- func RemoveElementFromList[S ~[]E, E comparable](list S, element E) S
- func RemoveSublistFromList[S ~[]E, E comparable](list, sublist S) S
- func SecondArg[S ~[]E, E comparable](args S) E
- func SplitPath(path string) []string
- func SplitUrls(s, sep string) []string
- func StringListInsert(list []string, element string, index int) []string
- func TerragruntExcludes(path string) bool
- func UniqueId() string
- func WriteFileWithSamePermissions(source string, destination string, contents []byte) error
- type FatalError
- type Lockfile
- type LogWriter
- type MaxRetriesExceeded
- type PathIsNotDirectory
- type PathIsNotFile
- type TrapWriter
Constants ¶
const ( TerraformLockFile = ".terraform.lock.hcl" TerragruntCacheDir = ".terragrunt-cache" DefaultBoilerplateDir = ".boilerplate" TfFileExtension = ".tf" )
const BASE_62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
const UNIQUE_ID_LENGTH = 6 // Should be good for 62^6 = 56+ billion combinations
Variables ¶
var ( // GlobalFallbackLogEntry is a global fallback logentry for the application // Should be used in cases when more specific logger can't be created (like in the very beginning, when we have not yet // parsed command line arguments). // // This might go away once we migrate toproper cli library // (see https://github.com/gruntwork-io/terragrunt/blob/master/cli/args.go#L29) GlobalFallbackLogEntry *logrus.Entry )
Functions ¶
func AsTerraformEnvVarJsonValue ¶ added in v0.42.4
Convert the given value to a JSON value that can be passed to Terraform as an environment variable. For the most part, this converts the value directly to JSON using Go's built-in json.Marshal. However, we have special handling for strings, which with normal JSON conversion would be wrapped in quotes, but when passing them to Terraform via env vars, we need to NOT wrap them in quotes, so this method adds special handling for that case.
func CanonicalPath ¶ added in v0.6.0
CanonicalPath returns the canonical version of the given path, relative to the given base path. That is, if the given path is a relative path, assume it is relative to the given base path. A canonical path is an absolute path with all relative components (e.g. "../") fully resolved, which makes it safe to compare paths as strings.
func CanonicalPaths ¶ added in v0.6.0
Return the canonical version of the given paths, relative to the given base path. That is, if a given path is a relative path, assume it is relative to the given base path. A canonical path is an absolute path with all relative components (e.g. "../") fully resolved, which makes it safe to compare paths as strings.
func CleanPath ¶ added in v0.9.0
Use this function when cleaning paths to ensure the returned path uses / as the path separator to improve cross-platform compatibility
func CloneStringList ¶ added in v0.13.19
Make a copy of the given list of strings
func CloneStringMap ¶ added in v0.13.19
Make a copy of the given map of strings
func CommaSeparatedStrings ¶ added in v0.12.17
CommaSeparatedStrings returns an HCL compliant formatted list of strings (each string within double quote)
func ContainsPath ¶ added in v0.23.24
ContainsPath returns true if path contains the given subpath E.g. path="foo/bar/bee", subpath="bar/bee" -> true E.g. path="foo/bar/bee", subpath="bar/be" -> false (because be is not a directory)
func CopyFolderContents ¶ added in v0.9.4
Copy the files and folders within the source folder into the destination folder. Note that hidden files and folders (those starting with a dot) will be skipped. Will create a specified manifest file that contains paths of all copied files.
func CopyFolderContentsWithFilter ¶ added in v0.19.0
func CopyFolderContentsWithFilter(source, destination, manifestFile string, filter func(absolutePath string) bool) error
Copy the files and folders within the source folder into the destination folder. Pass each file and folder through the given filter function and only copy it if the filter returns true. Will create a specified manifest file that contains paths of all copied files.
func CopyLockFile ¶ added in v0.45.12
Terraform 0.14 now generates a lock file when you run `terraform init`. If any such file exists, this function will copy the lock file to the destination folder
func CreateLogEntry ¶ added in v0.28.0
CreateLogEntry creates a logger entry with the given prefix field
func CreateLogEntryWithWriter ¶ added in v0.28.0
func CreateLogEntryWithWriter(writer io.Writer, prefix string, level logrus.Level, hooks logrus.LevelHooks) *logrus.Entry
CreateLogEntryWithWriter Create a logger around the given output stream and prefix
func CreateLogger ¶ added in v0.6.0
CreateLogger creates a logger. If debug is set, we use ErrorLevel to enable verbose output, otherwise - only errors are shown
func DisableJsonFormat ¶ added in v0.54.20
func DisableJsonFormat()
func DisableLogColors ¶ added in v0.48.7
func DisableLogColors()
func DoWithRetry ¶ added in v0.19.0
func DoWithRetry(ctx context.Context, actionDescription string, maxRetries int, sleepBetweenRetries time.Duration, logLevel logrus.Level, action func() error) error
DoWithRetry runs the specified action. If it returns a value, return that value. If it returns an error, sleep for sleepBetweenRetries and try again, up to a maximum of maxRetries retries. If maxRetries is exceeded, return a MaxRetriesExceeded error.
func EncodeBase64Sha1 ¶ added in v0.9.7
EncodeBase64Sha1 Returns the base 64 encoded sha1 hash of the given string
func EnsureDirectory ¶ added in v0.24.3
EnsureDirectory creates a directory at this path if it does not exist, or error if the path exists and is a file.
func FetchFile ¶ added in v0.56.4
FetchFile downloads the file from the given `downloadURL` into the specified `saveToFile` file.
func FileNotExists ¶ added in v0.21.6
Return true if the given file does not exist
func FileOrData ¶ added in v0.31.0
FileOrData will read the contents of the data of the given arg if it is a file, and otherwise return the contents by itself. This will return an error if the given path is a directory.
func FirstArg ¶ added in v0.16.7
func FirstArg[S ~[]E, E comparable](args S) E
A convenience method that returns the first item (0th index) in the given list or an empty string if this is an empty list
func FolderPathAsFile ¶ added in v0.57.4
FolderPathAsFile returns a cleaned version of the given folder path that can be used as a file name.
func GenerateRandomSha256 ¶ added in v0.38.4
func GetCacheDir ¶ added in v0.56.4
GetCacheDir returns the global terragrunt cache directory for the current user.
func GetDefaultLogLevel ¶ added in v0.31.11
GetDefaultLogLevel returns the default log level to use. The log level is resolved based on the environment variable with name from LogLevelEnvVar, falling back to info if unspecified or there is an error parsing the given log level.
func GetDiagnosticsWriter ¶ added in v0.19.14
GetDiagnosticsWriter returns a hcl2 parsing diagnostics emitter for the current terminal.
func GetPathRelativeTo ¶ added in v0.4.0
Return the relative path you would have to take to get from basePath to path
func GetRandomTime ¶ added in v0.6.4
Get a random time duration between the lower bound and upper bound. This is useful because some of our automated tests wound up flooding the AWS API all at once, leading to a "Subscriber limit exceeded" error. TODO: Some of the more exotic test cases fail, but it's not worth catching them given the intended use of this function.
func GlobCanonicalPath ¶ added in v0.50.1
GlobCanonicalPath returns the canonical versions of the given glob paths, relative to the given base path.
func Grep ¶
Returns true if the given regex can be found in any of the files matched by the given glob
func HasPathPrefix ¶ added in v0.23.24
HasPathPrefix returns true if path starts with the given path prefix E.g. path="/foo/bar/biz", prefix="/foo/bar" -> true E.g. path="/foo/bar/biz", prefix="/foo/ba" -> false (because ba is not a directory path)
func IsCommandExecutable ¶ added in v0.52.0
IsCommandExecutable - returns true if a command can be executed without errors.
func IsDirectoryEmpty ¶ added in v0.54.0
IsDirectoryEmpty - returns true if the given path exists and is a empty directory.
func IsSymLink ¶ added in v0.19.0
IsSymLink returns true if the given file is a symbolic link Per https://stackoverflow.com/a/18062079/2308858
func JoinPath ¶ added in v0.9.0
Windows systems use \ as the path separator *nix uses / Use this function when joining paths to force the returned path to use / as the path separator This will improve cross-platform compatibility
func JoinTerraformModulePath ¶ added in v0.13.13
Join two paths together with a double-slash between them, as this is what Terraform uses to identify where a "repo" ends and a path within the repo begins. Note: The Terraform docs only mention two forward-slashes, so it's not clear if on Windows those should be two back-slashes? https://www.terraform.io/docs/modules/sources.html
func JsonFormat ¶ added in v0.54.20
func JsonFormat()
func LastArg ¶ added in v0.16.14
func LastArg[S ~[]E, E comparable](args S) E
A convenience method that returns the last item in the given list or an empty string if this is an empty list
func ListContainsElement ¶ added in v0.6.0
func ListContainsElement[S ~[]E, E comparable](list S, element any) bool
ListContainsElement returns true if the given list contains the given element
func ListContainsSublist ¶ added in v0.23.24
func ListContainsSublist[S ~[]E, E comparable](list, sublist S) bool
ListContainsSublist returns true if an instance of the sublist can be found in the given list
func ListEquals ¶ added in v0.23.24
func ListEquals[S ~[]E, E comparable](a, b S) bool
ListEquals returns true if the two lists are equal
func ListHasPrefix ¶ added in v0.23.24
func ListHasPrefix[S ~[]E, E comparable](list, prefix S) bool
ListHasPrefix returns true if list starts with the given prefix list
func ListTfFiles ¶ added in v0.54.0
ListTfFiles returns a list of all TF files in the specified directory.
func MatchesAny ¶ added in v0.17.0
func MustWalkTerraformOutput ¶ added in v0.36.2
func MustWalkTerraformOutput(value interface{}, path ...string) interface{}
MustWalkTerraformOutput is a helper utility to deeply return a value from a terraform output.
nil will be returned if the path is invalid Using an example terraform output: a = { b = { c = "foo" } "d" = [ 1, 2 ] } path ["a", "b", "c"] will return "foo" path ["a", "d", "1"] will return 2 path ["a", "foo"] will return nil
func ParseLogLevel ¶ added in v0.48.7
func PrefixedWriter ¶ added in v0.45.1
func ReadFileAsString ¶ added in v0.4.0
Return the contents of the file at the given path as a string
func RemoveDuplicatesFromList ¶ added in v0.12.11
func RemoveDuplicatesFromList[S ~[]E, E comparable](list S) S
Returns a copy of the given list with all duplicates removed (keeping the first encountereds)
func RemoveDuplicatesFromListKeepLast ¶ added in v0.12.11
func RemoveDuplicatesFromListKeepLast[S ~[]E, E comparable](list S) S
Returns a copy of the given list with all duplicates removed (keeping the last encountereds)
func RemoveElementFromList ¶ added in v0.6.0
func RemoveElementFromList[S ~[]E, E comparable](list S, element E) S
Return a copy of the given list with all instances of the given element removed
func RemoveSublistFromList ¶ added in v0.56.4
func RemoveSublistFromList[S ~[]E, E comparable](list, sublist S) S
RemoveSublistFromList returns a copy of the given list with all instances of the given sublist removed
func SecondArg ¶ added in v0.16.7
func SecondArg[S ~[]E, E comparable](args S) E
A convenience method that returns the second item (1st index) in the given list or an empty string if this is a list that has less than 2 items in it
func SplitPath ¶ added in v0.23.24
SplitPath splits the given path into a list. E.g. "foo/bar/boo.txt" -> ["foo", "bar", "boo.txt"] E.g. "/foo/bar/boo.txt" -> ["", "foo", "bar", "boo.txt"] Notice that if path is absolute the resulting list will begin with an empty string.
func SplitUrls ¶ added in v0.46.2
SplitUrls slices s into all substrings separated by sep and returns a slice of the substrings between those separators. Taking into account that the `=` sign can also be used as a git tag, e.g. `git@github.com/test.git?ref=feature`
func StringListInsert ¶ added in v0.28.4
StringListInsert will insert the given string in to the provided string list at the specified index and return the new list of strings. To insert the element, we append the item to the tail of the string and then prepend the existing items.
func TerragruntExcludes ¶ added in v0.27.0
func UniqueId ¶ added in v0.19.0
func UniqueId() string
Returns a unique (ish) id we can use to name resources so they don't conflict with each other. Uses base 62 to generate a 6 character string that's unlikely to collide with the handful of tests we run in parallel. Based on code here: http://stackoverflow.com/a/9543797/483528
Types ¶
type FatalError ¶ added in v0.50.9
type FatalError struct {
Underlying error
}
FatalError is error interface for cases that should not be retried.
func (FatalError) Error ¶ added in v0.50.9
func (err FatalError) Error() string
type Lockfile ¶ added in v0.56.4
func NewLockfile ¶ added in v0.56.4
type LogWriter ¶ added in v0.35.5
LogWriter - Writer implementation which redirect Write requests to configured logger and level
type MaxRetriesExceeded ¶ added in v0.19.0
MaxRetriesExceeded is an error that occurs when the maximum amount of retries is exceeded.
func (MaxRetriesExceeded) Error ¶ added in v0.19.0
func (err MaxRetriesExceeded) Error() string
type PathIsNotDirectory ¶ added in v0.24.3
type PathIsNotDirectory struct {
// contains filtered or unexported fields
}
PathIsNotDirectory is returned when the given path is unexpectedly not a directory.
func (PathIsNotDirectory) Error ¶ added in v0.24.3
func (err PathIsNotDirectory) Error() string
type PathIsNotFile ¶ added in v0.31.0
type PathIsNotFile struct {
// contains filtered or unexported fields
}
PathIsNotFile is returned when the given path is unexpectedly not a file.
func (PathIsNotFile) Error ¶ added in v0.31.0
func (err PathIsNotFile) Error() string
type TrapWriter ¶ added in v0.56.4
type TrapWriter struct {
// contains filtered or unexported fields
}
TrapWriter intercepts any messages matching `reg` received from the `writer` output, but passes all others. Used when necessary to filter logs from terraform.
func NewTrapWriter ¶ added in v0.56.4
func NewTrapWriter(writer io.Writer, reg *regexp.Regexp) *TrapWriter
NewTrapWriter returns a new TrapWriter instance.
func (*TrapWriter) Clear ¶ added in v0.56.4
func (trap *TrapWriter) Clear()
Clear clears all intercepted messages.
func (*TrapWriter) Msgs ¶ added in v0.56.4
func (trap *TrapWriter) Msgs() []string
Msgs returns the intercepted messages.