run

package
v0.73.0-alpha2025020401 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package run contains the logic for interacting with OpenTofu/Terraform.

Package run provides Terragrunt command flags.

Index

Constants

View Source
const (
	CommandNameTerragruntReadConfig = "terragrunt-read-config"
	NullTFVarsFile                  = ".terragrunt-null-vars.auto.tfvars.json"
)
View Source
const (
	AllFlagName                            = "all"
	GraphFlagName                          = "graph"
	ConfigFlagName                         = "config"
	NoAutoInitFlagName                     = "no-auto-init"
	NoAutoRetryFlagName                    = "no-auto-retry"
	NoAutoApproveFlagName                  = "no-auto-approve"
	DownloadDirFlagName                    = "download-dir"
	TFForwardStdoutFlagName                = "tf-forward-stdout"
	TFPathFlagName                         = "tf-path"
	FeatureFlagName                        = "feature"
	ParallelismFlagName                    = "parallelism"
	InputsDebugFlagName                    = "inputs-debug"
	UnitsThatIncludeFlagName               = "units-that-include"
	DependencyFetchOutputFromStateFlagName = "dependency-fetch-output-from-state"
	UsePartialParseConfigCacheFlagName     = "use-partial-parse-config-cache"

	BackendRequireBootstrapFlagName = "backend-require-bootstrap"
	DisableBucketUpdateFlagName     = "disable-bucket-update"

	DisableCommandValidationFlagName   = "disable-command-validation"
	AuthProviderCmdFlagName            = "auth-provider-cmd"
	NoDestroyDependenciesCheckFlagName = "no-destroy-dependencies-check"

	SourceFlagName       = "source"
	SourceMapFlagName    = "source-map"
	SourceUpdateFlagName = "source-update"

	IAMAssumeRoleFlagName                 = "iam-assume-role"
	IAMAssumeRoleDurationFlagName         = "iam-assume-role-duration"
	IAMAssumeRoleSessionNameFlagName      = "iam-assume-role-session-name"
	IAMAssumeRoleWebIdentityTokenFlagName = "iam-assume-role-web-identity-token"

	QueueIgnoreErrorsFlagName        = "queue-ignore-errors"
	QueueIgnoreDAGOrderFlagName      = "queue-ignore-dag-order"
	QueueExcludeExternalFlagName     = "queue-exclude-external"
	QueueExcludeDirFlagName          = "queue-exclude-dir"
	QueueExcludesFileFlagName        = "queue-excludes-file"
	QueueIncludeDirFlagName          = "queue-include-dir"
	QueueIncludeExternalFlagName     = "queue-include-external"
	QueueStrictIncludeFlagName       = "queue-strict-include"
	QueueIncludeUnitsReadingFlagName = "queue-include-units-reading"

	ProviderCacheFlagName              = "provider-cache"
	ProviderCacheDirFlagName           = "provider-cache-dir"
	ProviderCacheHostnameFlagName      = "provider-cache-hostname"
	ProviderCachePortFlagName          = "provider-cache-port"
	ProviderCacheTokenFlagName         = "provider-cache-token"
	ProviderCacheRegistryNamesFlagName = "provider-cache-registry-names"

	EngineEnableFlagName    = "experimental-engine"
	EngineCachePathFlagName = "engine-cache-path"
	EngineSkipCheckFlagName = "engine-skip-check"
	EngineLogLevelFlagName  = "engine-log-level"

	DeprecatedFailOnStateBucketCreationFlagName      = "fail-on-state-bucket-creation"      // `backend-require-bootstrap`
	DeprecatedModulesThatIncludeFlagName             = "modules-that-include"               // `units-that-include`
	DeprecatedForwardTFStdoutFlagName                = "forward-tf-stdout"                  // `tf-forward-stdout`.
	DeprecatedTfpathFlagName                         = "tfpath"                             // `tf-path`.
	DeprecatedDownloadEnvVar                         = "DOWNLOAD"                           // `download-dir` for old `TERRAGRUNT_DOWNLOAD` env var.
	DeprecatedIAMRoleFlagName                        = "iam-role"                           // `iam-assume-role`.
	DeprecatedIAMWebIdentityTokenFlagName            = "iam-web-identity-token"             // `iam-assume-role-web-identity-token`.
	DeprecatedDebugFlagName                          = "debug"                              // `inputs-debug`.
	DeprecatedFetchDependencyOutputFromStateFlagName = "fetch-dependency-output-from-state" // `dependency-fetch-output-from-state`.
	DeprecatedIgnoreDependencyOrderFlagName          = "ignore-dependency-order"            // `queue-ignore-dag-order`.
	DeprecatedIgnoreExternalDependenciesFlagName     = "ignore-external-dependencies"       // `queue-exclude-external`.
	DeprecatedExcludeDirFlagName                     = "exclude-dir"                        // `queue-exclude-dir`.
	DeprecatedExcludesFileFlagName                   = "excludes-file"                      // `queue-excludes-file`.
	DeprecatedIncludeDirFlagName                     = "include-dir"                        // `queue-include-dir`.
	DeprecatedIncludeExternalDependenciesFlagName    = "include-external-dependencies"      // `queue-include-external`.
	DeprecatedStrictIncludeFlagName                  = "strict-include"                     // `queue-strict-include`.
	DeprecatedUnitsReadingFlagName                   = "queue-include-units-reading"        // `queue-include-units-reading`.
	DeprecatedIgnoreDependencyErrorsFlagName         = "ignore-dependency-errors"           // `queue-ignore-errors`.
	DeprecatedConfigFlagName                         = "config"
	DeprecatedDownloadDirFlagName                    = "download-dir"
	DeprecatedIAMAssumeRoleWebIdentityTokenFlagName  = "iam-assume-role-web-identity-token"
	DeprecatedSourceMapFlagName                      = "source-map"
	DeprecatedSourceUpdateFlagName                   = "source-update"
	DeprecatedSourceFlagName                         = "source"
	DeprecatedNoAutoApproveFlagName                  = "no-auto-approve"
	DeprecatedNoAutoRetryFlagName                    = "no-auto-retry"
	DeprecatedNoAutoInitFlagName                     = "no-auto-init"
	DeprecatedNoDestroyDependenciesCheckFlagName     = "no-destroy-dependencies-check"
	DeprecatedDisableCommandValidationFlagName       = "disable-command-validation"
	DeprecatedDisableBucketUpdateFlagName            = "disable-bucket-update"
	DeprecatedUsePartialParseConfigCacheFlagName     = "use-partial-parse-config-cache"
	DeprecatedParallelismFlagName                    = "parallelism"
	DeprecatedIAMAssumeRoleSessionNameFlagName       = "iam-assume-role-session-name"
	DeprecatedIAMAssumeRoleDurationFlagName          = "iam-assume-role-duration"
	DeprecatedProviderCacheFlagName                  = "provider-cache"
	DeprecatedProviderCacheDirFlagName               = "provider-cache-dir"
	DeprecatedProviderCacheHostnameFlagName          = "provider-cache-hostname"
	DeprecatedProviderCachePortFlagName              = "provider-cache-port"
	DeprecatedProviderCacheTokenFlagName             = "provider-cache-token"
	DeprecatedProviderCacheRegistryNamesFlagName     = "provider-cache-registry-names"
	DeprecatedFeatureFlagName                        = "feature"
	DeprecatedAuthProviderCmdFlagName                = "auth-provider-cmd"
	DeprecatedEngineEnableFlagName                   = "experimental-engine"
	DeprecatedEngineCachePathFlagName                = "engine-cache-path"
	DeprecatedEngineSkipCheckFlagName                = "engine-skip-check"
	DeprecatedEngineLogLevelFlagName                 = "engine-log-level"

	DeprecatedIncludeModulePrefixFlagName = "include-module-prefix"
)
View Source
const (
	HookCtxTFPathEnvName   = "TG_CTX_TF_PATH"
	HookCtxCommandEnvName  = "TG_CTX_COMMAND"
	HookCtxHookNameEnvName = "TG_CTX_HOOK_NAME"
)
View Source
const (
	CommandName = "run"
)
View Source
const DefaultTerraformVersionConstraint = ">= v0.12.0"

DefaultTerraformVersionConstraint uses the constraint syntax from https://github.com/hashicorp/go-version This version of Terragrunt was tested to work with Terraform 0.12.0 and above only

View Source
const ModuleInitRequiredFile = ".terragrunt-init-required"

ModuleInitRequiredFile is a file to indicate that init should be executed.

View Source
const ModuleManifestName = ".terragrunt-module-manifest"

ModuleManifestName is the manifest for files copied from terragrunt module folder (i.e., the folder that contains the current terragrunt.hcl).

View Source
const SourceManifestName = ".terragrunt-source-manifest"

SourceManifestName is the manifest for files copied from the URL specified in the terraform { source = "<URL>" } config

View Source
const TerraformExtensionGlob = "*.tf"
View Source
const TerragruntTFVarsFile = "terragrunt-debug.tfvars.json"

Variables

View Source
var ModuleRegex = regexp.MustCompile(`module[[:blank:]]+".+"`)
View Source
var TerraformCommandsThatDoNotNeedInit = []string{
	"version",
	"terragrunt-info",
	"graph-dependencies",
}
View Source
var TerraformCommandsThatUseState = []string{
	"init",
	"apply",
	"destroy",
	"env",
	"import",
	"graph",
	"output",
	"plan",
	"push",
	"refresh",
	"show",
	"taint",
	"untaint",
	"validate",
	"force-unlock",
	"state",
}
View Source
var TerraformVersionRegex = regexp.MustCompile(`^(\S+)\s(v?\d+\.\d+\.\d+)`)

TerraformVersionRegex verifies that terraform --version output is in one of the following formats: - OpenTofu v1.6.0-dev - Terraform v0.9.5-dev (cad024a5fe131a546936674ef85445215bbc4226+CHANGES) - Terraform v0.13.0-beta2 - Terraform v0.12.27 We only make sure the "v#.#.#" part is present in the output.

Functions

func Action

func AlreadyHaveLatestCode

func AlreadyHaveLatestCode(terraformSource *tf.Source, terragruntOptions *options.TerragruntOptions) (bool, error)

AlreadyHaveLatestCode returns true if the specified TerraformSource, of the exact same version, has already been downloaded into the DownloadFolder. This helps avoid downloading the same code multiple times. Note that if the TerraformSource points to a local file path, a hash will be generated from the contents of the source dir. See the ProcessTerraformSource method for more info.

func CheckFolderContainsTerraformCode

func CheckFolderContainsTerraformCode(terragruntOptions *options.TerragruntOptions) error

func CheckTerraformVersion

func CheckTerraformVersion(constraint string, terragruntOptions *options.TerragruntOptions) error

CheckTerraformVersion checks that the currently installed Terraform version works meets the specified version constraint and return an error if it doesn't

func CheckTerraformVersionMeetsConstraint

func CheckTerraformVersionMeetsConstraint(currentVersion *version.Version, constraint string) error

CheckTerraformVersionMeetsConstraint checks that the current version of Terraform meets the specified constraint and return an error if it doesn't

func CheckTerragruntVersion

func CheckTerragruntVersion(constraint string, terragruntOptions *options.TerragruntOptions) error

CheckTerragruntVersion checks that the currently running Terragrunt version meets the specified version constraint and return an error if it doesn't

func CheckTerragruntVersionMeetsConstraint

func CheckTerragruntVersionMeetsConstraint(currentVersion *version.Version, constraint string) error

CheckTerragruntVersionMeetsConstraint checks that the current version of Terragrunt meets the specified constraint and return an error if it doesn't

func CheckVersionConstraints

func CheckVersionConstraints(ctx context.Context, terragruntOptions *options.TerragruntOptions) error

CheckVersionConstraints checks the version constraints of both terragrunt and terraform. Note that as a side effect this will set the following settings on terragruntOptions: - TerraformPath - TerraformVersion - FeatureFlags TODO: Look into a way to refactor this function to avoid the side effect.

func DownloadTerraformSourceIfNecessary

func DownloadTerraformSourceIfNecessary(ctx context.Context, terraformSource *tf.Source, terragruntOptions *options.TerragruntOptions, terragruntConfig *config.TerragruntConfig) error

DownloadTerraformSourceIfNecessary downloads the specified TerraformSource if the latest code hasn't already been downloaded.

func FilterTerraformExtraArgs

func FilterTerraformExtraArgs(terragruntOptions *options.TerragruntOptions, terragruntConfig *config.TerragruntConfig) []string

func IsRetryable

func IsRetryable(opts *options.TerragruntOptions, out *util.CmdOutput) bool

IsRetryable checks whether there was an error and if the output matches any of the configured RetryableErrors

func NewCommand

func NewCommand(opts *options.TerragruntOptions) *cli.Command

func NewFlags

func NewFlags(opts *options.TerragruntOptions, prefix flags.Prefix) cli.Flags

NewFlags creates and returns global flags.

func NewSubcommands

func NewSubcommands(opts *options.TerragruntOptions) cli.Commands

func ParseTerraformVersion

func ParseTerraformVersion(versionCommandOutput string) (*version.Version, error)

ParseTerraformVersion parses the output of the terraform --version command

func PopulateTerraformVersion

func PopulateTerraformVersion(ctx context.Context, terragruntOptions *options.TerragruntOptions) error

PopulateTerraformVersion populates the currently installed version of Terraform into the given terragruntOptions.

func Run

Run downloads terraform source if necessary, then runs terraform with the given options and CLI args. This will forward all the args and extra_arguments directly to Terraform.

func RunActionWithHooks

func RunActionWithHooks(ctx context.Context, description string, terragruntOptions *options.TerragruntOptions, terragruntConfig *config.TerragruntConfig, action func(ctx context.Context) error) error

RunActionWithHooks runs the given action function surrounded by hooks. That is, run the before hooks first, then, if there were no errors, run the action, and finally, run the after hooks. Return any errors hit from the hooks or action.

func RunTerraformWithRetry

func RunTerraformWithRetry(ctx context.Context, terragruntOptions *options.TerragruntOptions) error

func RunWithTarget

func RunWithTarget(ctx context.Context, opts *options.TerragruntOptions, target *Target) error

func SetTerragruntInputsAsEnvVars

func SetTerragruntInputsAsEnvVars(terragruntOptions *options.TerragruntOptions, terragruntConfig *config.TerragruntConfig) error

SetTerragruntInputsAsEnvVars sets the inputs from Terragrunt configurations to TF_VAR_* environment variables for OpenTofu/Terraform.

func ShouldCopyLockFile

func ShouldCopyLockFile(args cli.Args, terraformConfig *config.TerraformConfig) bool

ShouldCopyLockFile verifies if the lock file should be copied to the user's working directory Terraform 0.14 now manages a lock file for providers. This can be updated in three ways: * `terraform init` in a module where no `.terraform.lock.hcl` exists * `terraform init -upgrade` * `terraform providers lock`

In any of these cases, terragrunt should attempt to copy the generated `.terraform.lock.hcl`

terraform init is not guaranteed to pull all checksums depending on platforms, if you already have the provider requested in a cache, or if you are using a mirror. There are lots of details at [hashicorp/terraform#27264](https://github.com/hashicorp/terraform/issues/27264#issuecomment-743389837) The `providers lock` sub command enables you to ensure that the lock file is fully populated.

func ShowTFHelp

func ShowTFHelp(opts *options.TerragruntOptions) cli.HelpFunc

ShowTFHelp prints TF help for the given `ctx.Command` command.

func ToTerraformEnvVars

func ToTerraformEnvVars(opts *options.TerragruntOptions, vars map[string]interface{}) (map[string]string, error)

ToTerraformEnvVars converts the given variables to a map of environment variables that will expose those variables to Terraform. The keys will be of the format TF_VAR_xxx and the values will be converted to JSON, which Terraform knows how to read natively.

func UpdateGetters

func UpdateGetters(terragruntOptions *options.TerragruntOptions, terragruntConfig *config.TerragruntConfig) func(*getter.Client) error

UpdateGetters returns the customized go-getter interfaces that Terragrunt relies on. Specifically:

  • Local file path getter is updated to copy the files instead of creating symlinks, which is what go-getter defaults to.
  • Include the customized getter for fetching sources from the Terraform Registry.

This creates a closure that returns a function so that we have access to the terragrunt configuration, which is necessary for customizing the behavior of the file getter.

func ValidateWorkingDir

func ValidateWorkingDir(terraformSource *tf.Source) error

ValidateWorkingDir checks if working terraformSource.WorkingDir exists and is directory

func WriteTerragruntDebugFile

func WriteTerragruntDebugFile(terragruntOptions *options.TerragruntOptions, terragruntConfig *config.TerragruntConfig) error

WriteTerragruntDebugFile will create a tfvars file that can be used to invoke the terraform module in the same way that terragrunt invokes the module, so that you can debug issues with the terragrunt config.

Types

type BackendNotDefined

type BackendNotDefined struct {
	Opts        *options.TerragruntOptions
	BackendType string
}

func (BackendNotDefined) Error

func (err BackendNotDefined) Error() string

type DownloadingTerraformSourceErr

type DownloadingTerraformSourceErr struct {
	ErrMsg error
	URL    string
}

func (DownloadingTerraformSourceErr) Error

type FileCopyGetter

type FileCopyGetter struct {
	getter.FileGetter

	// List of glob paths that should be included in the copy. This can be used to override the default behavior of
	// Terragrunt, which will skip hidden folders.
	IncludeInCopy   []string
	ExcludeFromCopy []string

	Logger log.Logger
}

FileCopyGetter is a custom getter.Getter implementation that uses file copying instead of symlinks. Symlinks are faster and use less disk space, but they cause issues in Windows and with infinite loops, so we copy files/folders instead.

func (*FileCopyGetter) Get

func (g *FileCopyGetter) Get(dst string, u *url.URL) error

Get replaces the original FileGetter The original FileGetter does NOT know how to do folder copying (it only does symlinks), so we provide a copy implementation here

func (*FileCopyGetter) GetFile

func (g *FileCopyGetter) GetFile(dst string, u *url.URL) error

GetFile The original FileGetter already knows how to do file copying so long as we set the Copy flag to true, so just delegate to it

type InvalidTerraformVersion

type InvalidTerraformVersion struct {
	CurrentVersion     *version.Version
	VersionConstraints version.Constraints
}

func (InvalidTerraformVersion) Error

func (err InvalidTerraformVersion) Error() string

type InvalidTerraformVersionSyntax

type InvalidTerraformVersionSyntax string

func (InvalidTerraformVersionSyntax) Error

type InvalidTerragruntVersion

type InvalidTerragruntVersion struct {
	CurrentVersion     *version.Version
	VersionConstraints version.Constraints
}

func (InvalidTerragruntVersion) Error

func (err InvalidTerragruntVersion) Error() string

type MaxRetriesExceeded

type MaxRetriesExceeded struct {
	Opts *options.TerragruntOptions
}

func (MaxRetriesExceeded) Error

func (err MaxRetriesExceeded) Error() string

type MissingCommand

type MissingCommand struct{}

func (MissingCommand) Error

func (err MissingCommand) Error() string

type ModuleIsProtected

type ModuleIsProtected struct {
	Opts *options.TerragruntOptions
}

func (ModuleIsProtected) Error

func (err ModuleIsProtected) Error() string

type NoTerraformFilesFound

type NoTerraformFilesFound string

func (NoTerraformFilesFound) Error

func (path NoTerraformFilesFound) Error() string

type RunAllDisabledErr

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

func (RunAllDisabledErr) Error

func (err RunAllDisabledErr) Error() string

type Target

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

func NewTarget

func NewTarget(point TargetPointType, callbackFunc TargetCallbackType) *Target

func NewTargetWithErrorHandler

func NewTargetWithErrorHandler(point TargetPointType, callbackFunc TargetCallbackType, errorCallbackFunc TargetErrorCallbackType) *Target

type TargetCallbackType

type TargetCallbackType func(ctx context.Context, opts *options.TerragruntOptions, config *config.TerragruntConfig) error

type TargetErrorCallbackType

type TargetErrorCallbackType func(opts *options.TerragruntOptions, config *config.TerragruntConfig, e error) error

type TargetPointType

type TargetPointType byte
const (
	TargetPointParseConfig TargetPointType = iota + 1
	TargetPointDownloadSource
	TargetPointGenerateConfig
	TargetPointSetInputsAsEnvVars
	TargetPointInitCommand
)

type WorkingDirNotDir

type WorkingDirNotDir struct {
	Source string
	Dir    string
}

func (WorkingDirNotDir) Error

func (err WorkingDirNotDir) Error() string

type WorkingDirNotFound

type WorkingDirNotFound struct {
	Source string
	Dir    string
}

func (WorkingDirNotFound) Error

func (err WorkingDirNotFound) Error() string

type WrongTerraformCommand

type WrongTerraformCommand string

func (WrongTerraformCommand) Error

func (name WrongTerraformCommand) Error() string

type WrongTofuCommand

type WrongTofuCommand string

func (WrongTofuCommand) Error

func (name WrongTofuCommand) Error() string

Directories

Path Synopsis
Package creds provides a way to obtain credentials through different providers and set them to `opts.Env`.
Package creds provides a way to obtain credentials through different providers and set them to `opts.Env`.
providers
Package providers defines the interface for a provider.
Package providers defines the interface for a provider.
providers/amazonsts
Package amazonsts provides a credentials provider that obtains credentials by making API requests to Amazon STS.
Package amazonsts provides a credentials provider that obtains credentials by making API requests to Amazon STS.
providers/externalcmd
Package externalcmd provides a provider that runs an external command that returns a json string with credentials.
Package externalcmd provides a provider that runs an external command that returns a json string with credentials.

Jump to

Keyboard shortcuts

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