terraform

package
v0.13.15 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package terraform allows to interact with Terraform.

Index

Constants

View Source
const DefaultErrorExitCode = 1

DefaultErrorExitCode is the exit code returned when terraform command fails

View Source
const DefaultSuccessExitCode = 0

DefaultSuccessExitCode is the exit code returned when terraform command succeeds

View Source
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

func Apply(t *testing.T, options *Options) string

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

func ApplyE(t *testing.T, options *Options) (string, error)

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 Destroy

func Destroy(t *testing.T, options *Options) string

Destroy runs terraform destroy with the given options and return stdout/stderr.

func DestroyE

func DestroyE(t *testing.T, options *Options) (string, error)

DestroyE runs terraform destroy with the given options and return stdout/stderr.

func FormatArgs

func FormatArgs(customVars map[string]interface{}, args ...string) []string

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 FormatTerraformBackendConfigAsArgs added in v0.9.13

func FormatTerraformBackendConfigAsArgs(vars map[string]interface{}) []string

FormatTerraformBackendConfigAsArgs formats the given variables as backend config args for Terraform (e.g. of the format -backend-config key=value).

func FormatTerraformVarsAsArgs

func FormatTerraformVarsAsArgs(vars map[string]interface{}) []string

FormatTerraformVarsAsArgs formats the given variables as command-line args for Terraform (e.g. of the format -var key=value).

func Get

func Get(t *testing.T, options *Options) string

Get calls terraform get and return stdout/stderr.

func GetE

func GetE(t *testing.T, options *Options) (string, error)

GetE calls terraform get and return stdout/stderr.

func GetExitCodeForTerraformCommand added in v0.10.4

func GetExitCodeForTerraformCommand(t *testing.T, additionalOptions *Options, args ...string) int

GetExitCodeForTerraformCommand runs terraform with the given arguments and options and returns exit code

func GetExitCodeForTerraformCommandE added in v0.10.4

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 Init

func Init(t *testing.T, options *Options) string

Init calls terraform init and return stdout/stderr.

func InitAndApply

func InitAndApply(t *testing.T, options *Options) string

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

func InitAndApplyE(t *testing.T, options *Options) (string, error)

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 added in v0.10.4

func InitAndPlan(t *testing.T, options *Options) int

InitAndPlan runs terraform init and plan with the given options and return stdout/stderr from the apply command.

func InitAndPlanE added in v0.10.4

func InitAndPlanE(t *testing.T, options *Options) (int, error)

InitAndPlanE runs terraform init and plan with the given options and return stdout/stderr from the apply command.

func InitE

func InitE(t *testing.T, options *Options) (string, error)

InitE calls terraform init and return stdout/stderr.

func Output

func Output(t *testing.T, options *Options, key string) string

Output calls terraform output for the given variable and return its value.

func OutputE

func OutputE(t *testing.T, options *Options, key string) (string, error)

OutputE calls terraform output for the given variable and return its value.

func OutputList added in v0.13.1

func OutputList(t *testing.T, options *Options, key string) []string

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 added in v0.13.1

func OutputListE(t *testing.T, options *Options, key string) ([]string, error)

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 added in v0.13.6

func OutputMap(t *testing.T, options *Options, key string) map[string]string

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 added in v0.13.6

func OutputMapE(t *testing.T, options *Options, key string) (map[string]string, error)

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

func OutputRequired(t *testing.T, options *Options, key string) string

OutputRequired calls terraform output for the given variable and return its value. If the value is empty, fail the test.

func OutputRequiredE

func OutputRequiredE(t *testing.T, options *Options, key string) (string, error)

OutputRequiredE calls terraform output for the given variable and return its value. If the value is empty, return an error.

func PlanExitCode added in v0.10.4

func PlanExitCode(t *testing.T, options *Options) int

PlanExitCode runs terraform apply with the given options and returns the detailed exitcode.

func PlanExitCodeE added in v0.10.4

func PlanExitCodeE(t *testing.T, options *Options) (int, error)

PlanExitCodeE runs terraform apply with the given options and returns the detailed exitcode.

func RunTerraformCommand added in v0.9.2

func RunTerraformCommand(t *testing.T, additionalOptions *Options, args ...string) string

RunTerraformCommand runs terraform with the given arguments and options and return stdout/stderr.

func RunTerraformCommandE added in v0.9.2

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 WorkspaceSelectOrNew added in v0.12.2

func WorkspaceSelectOrNew(t *testing.T, options *Options, name string) string

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 added in v0.12.2

func WorkspaceSelectOrNewE(t *testing.T, options *Options, name string) (string, error)

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 {
	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.
	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 text to look for in the error and the message is what to display to a user if that error is found.
	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
}

Options for running Terraform commands

func GetCommonOptions added in v0.10.4

func GetCommonOptions(options *Options, args ...string) (*Options, []string)

GetCommonOptions extracts commons terraform options

Jump to

Keyboard shortcuts

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