Documentation ¶
Overview ¶
Package terraform allows to interact with Terraform.
Index ¶
- Constants
- func Apply(t *testing.T, options *Options) string
- func ApplyE(t *testing.T, options *Options) (string, error)
- func Destroy(t *testing.T, options *Options) string
- func DestroyE(t *testing.T, options *Options) (string, error)
- func FormatArgs(options *Options, args ...string) []string
- func FormatTerraformArgs(argName string, args []string) []string
- func FormatTerraformBackendConfigAsArgs(vars map[string]interface{}) []string
- func FormatTerraformVarsAsArgs(vars map[string]interface{}) []string
- func Get(t *testing.T, options *Options) string
- func GetE(t *testing.T, options *Options) (string, error)
- func GetExitCodeForTerraformCommand(t *testing.T, additionalOptions *Options, args ...string) int
- func GetExitCodeForTerraformCommandE(t *testing.T, additionalOptions *Options, additionalArgs ...string) (int, error)
- func Init(t *testing.T, options *Options) string
- func InitAndApply(t *testing.T, options *Options) string
- func InitAndApplyE(t *testing.T, options *Options) (string, error)
- func InitAndPlan(t *testing.T, options *Options) string
- func InitAndPlanE(t *testing.T, options *Options) (string, error)
- func InitAndPlanWithExitCode(t *testing.T, options *Options) int
- func InitAndPlanWithExitCodeE(t *testing.T, options *Options) (int, error)
- func InitE(t *testing.T, options *Options) (string, error)
- func Output(t *testing.T, options *Options, key string) string
- func OutputAll(t *testing.T, options *Options) map[string]interface{}
- func OutputAllE(t *testing.T, options *Options) (map[string]interface{}, error)
- func OutputE(t *testing.T, options *Options, key string) (string, error)
- func OutputForKeys(t *testing.T, options *Options, keys []string) map[string]interface{}
- func OutputForKeysE(t *testing.T, options *Options, keys []string) (map[string]interface{}, error)
- func OutputList(t *testing.T, options *Options, key string) []string
- func OutputListE(t *testing.T, options *Options, key string) ([]string, error)
- func OutputMap(t *testing.T, options *Options, key string) map[string]string
- func OutputMapE(t *testing.T, options *Options, key string) (map[string]string, error)
- func OutputRequired(t *testing.T, options *Options, key string) string
- func OutputRequiredE(t *testing.T, options *Options, key string) (string, error)
- func Plan(t *testing.T, options *Options) string
- func PlanE(t *testing.T, options *Options) (string, error)
- func PlanExitCode(t *testing.T, options *Options) int
- func PlanExitCodeE(t *testing.T, options *Options) (int, error)
- func RunTerraformCommand(t *testing.T, additionalOptions *Options, args ...string) string
- func RunTerraformCommandAndGetStdoutE(t *testing.T, additionalOptions *Options, additionalArgs ...string) (string, error)
- func RunTerraformCommandE(t *testing.T, additionalOptions *Options, additionalArgs ...string) (string, error)
- func TgApplyAll(t *testing.T, options *Options) string
- func TgApplyAllE(t *testing.T, options *Options) (string, error)
- func TgDestroyAll(t *testing.T, options *Options) string
- func TgDestroyAllE(t *testing.T, options *Options) (string, error)
- func TgPlanAllExitCode(t *testing.T, options *Options) int
- func TgPlanAllExitCodeE(t *testing.T, options *Options) (int, error)
- func WorkspaceSelectOrNew(t *testing.T, options *Options, name string) string
- func WorkspaceSelectOrNewE(t *testing.T, options *Options, name string) (string, error)
- type EmptyOutput
- type Options
- type OutputKeyNotFound
- type OutputValueNotList
- type OutputValueNotMap
- type ResourceCount
- type TgInvalidBinary
- type UnexpectedOutputType
Constants ¶
const DefaultErrorExitCode = 1
DefaultErrorExitCode is the exit code returned when terraform command fails
const DefaultSuccessExitCode = 0
DefaultSuccessExitCode is the exit code returned when terraform command succeeds
const TerraformPlanChangesPresentExitCode = 2
TerraformPlanChangesPresentExitCode is the exit code returned by terraform plan detailed exitcode when changes are present
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply runs terraform apply with the given options and return stdout/stderr. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func ApplyE ¶
ApplyE runs terraform apply with the given options and return stdout/stderr. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func FormatArgs ¶
FormatArgs converts the inputs to a format palatable to terraform. This includes converting the given vars to the format the Terraform CLI expects (-var key=value).
func FormatTerraformArgs ¶
FormatTerraformArgs will format multiple args with the arg name (e.g. "-var-file", []string{"foo.tfvars", "bar.tfvars"}) returns "-var-file foo.tfvars -var-file bar.tfvars"
func FormatTerraformBackendConfigAsArgs ¶
FormatTerraformBackendConfigAsArgs formats the given variables as backend config args for Terraform (e.g. of the format -backend-config=key=value).
func FormatTerraformVarsAsArgs ¶
FormatTerraformVarsAsArgs formats the given variables as command-line args for Terraform (e.g. of the format -var key=value).
func GetExitCodeForTerraformCommand ¶
GetExitCodeForTerraformCommand runs terraform with the given arguments and options and returns exit code
func GetExitCodeForTerraformCommandE ¶
func GetExitCodeForTerraformCommandE(t *testing.T, additionalOptions *Options, additionalArgs ...string) (int, error)
GetExitCodeForTerraformCommandE runs terraform with the given arguments and options and returns exit code
func InitAndApply ¶
InitAndApply runs terraform init and apply with the given options and return stdout/stderr from the apply command. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func InitAndApplyE ¶
InitAndApplyE runs terraform init and apply with the given options and return stdout/stderr from the apply command. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func InitAndPlan ¶
InitAndPlan runs terraform init and plan with the given options and returns stdout/stderr from the plan command. This will fail the test if there is an error in the command.
func InitAndPlanE ¶
InitAndPlanE runs terraform init and plan with the given options and returns stdout/stderr from the plan command.
func InitAndPlanWithExitCode ¶
InitAndPlanWithExitCode runs terraform init and plan with the given options and returns exitcode for the plan command. This will fail the test if there is an error in the command.
func InitAndPlanWithExitCodeE ¶
InitAndPlanWithExitCodeE runs terraform init and plan with the given options and returns exitcode for the plan command.
func OutputAll ¶
OutputAll calls terraform output returns all values as a map. If there is error fetching the output, fails the test
func OutputAllE ¶
OutputAllE calls terraform and returns all the outputs as a map
func OutputForKeys ¶
OutputForKeys calls terraform output for the given key list and returns values as a map. If keys not found in the output, fails the test
func OutputForKeysE ¶
OutputForKeysE calls terraform output for the given key list and returns values as a map. The returned values are of type interface{} and need to be type casted as necessary. Refer to output_test.go
func OutputList ¶
OutputList calls terraform output for the given variable and returns its value as a list. If the output value is not a list type, then it fails the test.
func OutputListE ¶
OutputListE calls terraform output for the given variable and returns its value as a list. If the output value is not a list type, then it returns an error.
func OutputMap ¶
OutputMap calls terraform output for the given variable and returns its value as a map. If the output value is not a map type, then it fails the test.
func OutputMapE ¶
OutputMapE calls terraform output for the given variable and returns its value as a map. If the output value is not a map type, then it returns an error.
func OutputRequired ¶
OutputRequired calls terraform output for the given variable and return its value. If the value is empty, fail the test.
func OutputRequiredE ¶
OutputRequiredE calls terraform output for the given variable and return its value. If the value is empty, return an error.
func Plan ¶
Plan runs terraform plan with the given options and returns stdout/stderr. This will fail the test if there is an error in the command.
func PlanExitCode ¶
PlanExitCode runs terraform plan with the given options and returns the detailed exitcode. This will fail the test if there is an error in the command.
func PlanExitCodeE ¶
PlanExitCodeE runs terraform plan with the given options and returns the detailed exitcode.
func RunTerraformCommand ¶
RunTerraformCommand runs terraform with the given arguments and options and return stdout/stderr.
func RunTerraformCommandAndGetStdoutE ¶
func RunTerraformCommandAndGetStdoutE(t *testing.T, additionalOptions *Options, additionalArgs ...string) (string, error)
RunTerraformCommandAndGetStdoutE runs terraform with the given arguments and options and returns solely its stdout (but not stderr).
func RunTerraformCommandE ¶
func RunTerraformCommandE(t *testing.T, additionalOptions *Options, additionalArgs ...string) (string, error)
RunTerraformCommandE runs terraform with the given arguments and options and return stdout/stderr.
func TgApplyAll ¶
TgApplyAll runs terragrunt apply with the given options and return stdout/stderr. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func TgApplyAllE ¶
TgApplyAllE runs terragrunt apply-all with the given options and return stdout/stderr. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func TgDestroyAll ¶
TgDestroyAll runs terragrunt destroy with the given options and return stdout.
func TgDestroyAllE ¶
TgDestroyAllE runs terragrunt destroy with the given options and return stdout.
func TgPlanAllExitCode ¶
TgPlanAllExitCode runs terragrunt plan-all with the given options and returns the detailed exitcode. This will fail the test if there is an error in the command.
func TgPlanAllExitCodeE ¶
TgPlanAllExitCodeE runs terragrunt plan-all with the given options and returns the detailed exitcode.
func WorkspaceSelectOrNew ¶
WorkspaceSelectOrNew runs terraform workspace with the given options and the workspace name and returns a name of the current workspace. It tries to select a workspace with the given name, or it creates a new one if it doesn't exist.
func WorkspaceSelectOrNewE ¶
WorkspaceSelectOrNewE runs terraform workspace with the given options and the workspace name and returns a name of the current workspace. It tries to select a workspace with the given name, or it creates a new one if it doesn't exist.
Types ¶
type EmptyOutput ¶
type EmptyOutput string
EmptyOutput is an error that occurs when an output is empty.
func (EmptyOutput) Error ¶
func (outputName EmptyOutput) Error() string
type Options ¶
type Options struct { TerraformBinary string // Name of the binary that will be used TerraformDir string // The path to the folder where the Terraform code is defined. Vars map[string]interface{} // The vars to pass to Terraform commands using the -var option. VarFiles []string // The var file paths to pass to Terraform commands using -var-file option. Targets []string // The target resources to pass to the terraform command with -target EnvVars map[string]string // Environment variables to set when running Terraform BackendConfig map[string]interface{} // The vars to pass to the terraform init command for extra configuration for the backend RetryableTerraformErrors map[string]string // If Terraform apply fails with one of these (transient) errors, retry. The keys are a regexp to match against the error and the message is what to display to a user if that error is matched. MaxRetries int // Maximum number of times to retry errors matching RetryableTerraformErrors TimeBetweenRetries time.Duration // The amount of time to wait between retries Upgrade bool // Whether the -upgrade flag of the terraform init command should be set to true or not NoColor bool // Whether the -no-color flag will be set for any Terraform command or not SshAgent *ssh.SshAgent // Overrides local SSH agent with the given in-process agent NoStderr bool // Disable stderr redirection OutputMaxLineSize int // The max size of one line in stdout and stderr (in bytes) }
Options for running Terraform commands
type OutputKeyNotFound ¶
type OutputKeyNotFound string
OutputKeyNotFound occurs when terraform output does not contain a value for the key specified in the function call
func (OutputKeyNotFound) Error ¶
func (err OutputKeyNotFound) Error() string
type OutputValueNotList ¶
type OutputValueNotList struct {
Value interface{}
}
OutputValueNotList occurs when casting a found output value to a list of interfaces fails
func (OutputValueNotList) Error ¶
func (err OutputValueNotList) Error() string
type OutputValueNotMap ¶
type OutputValueNotMap struct {
Value interface{}
}
OutputValueNotMap occures when casting a found output value to a map fails
func (OutputValueNotMap) Error ¶
func (err OutputValueNotMap) Error() string
type ResourceCount ¶
ResourceCount represents counts of resources affected by terraform apply/plan/destroy command.
func GetResourceCount ¶
func GetResourceCount(t *testing.T, cmdout string) *ResourceCount
GetResourceCount parses stdout/stderr of apply/plan/destroy commands and returns number of affected resources. This will fail the test if given stdout/stderr isn't a valid output of apply/plan/destroy.
func GetResourceCountE ¶
func GetResourceCountE(t *testing.T, cmdout string) (*ResourceCount, error)
GetResourceCountE parses stdout/stderr of apply/plan/destroy commands and returns number of affected resources.
type TgInvalidBinary ¶
type TgInvalidBinary string
TgInvalidBinary occurs when a terragrunt function is called and the TerraformBinary is set to a value other than terragrunt
func (TgInvalidBinary) Error ¶
func (err TgInvalidBinary) Error() string
type UnexpectedOutputType ¶
UnexpectedOutputType is an error that occurs when the output is not of the type we expect
func (UnexpectedOutputType) Error ¶
func (err UnexpectedOutputType) Error() string