Documentation
¶
Overview ¶
Package terraform allows to interact with Terraform.
Index ¶
- Constants
- Variables
- func Apply(t testing.TestingT, options *Options) stringdeprecated
- func ApplyAndIdempotent(t testing.TestingT, options *Options) stringdeprecated
- func ApplyAndIdempotentContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ApplyAndIdempotentContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ApplyAndIdempotentE(t testing.TestingT, options *Options) (string, error)deprecated
- func ApplyContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ApplyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ApplyE(t testing.TestingT, options *Options) (string, error)deprecated
- func AssertPlannedValuesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
- func AssertResourceChangesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
- func Destroy(t testing.TestingT, options *Options) stringdeprecated
- func DestroyContext(t testing.TestingT, ctx context.Context, options *Options) string
- func DestroyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func DestroyE(t testing.TestingT, options *Options) (string, error)deprecated
- func FormatArgs(options *Options, args ...string) []string
- func FormatTerraformArgs(argName string, args []string) []string
- func FormatTerraformBackendConfigAsArgs(vars map[string]any) []string
- func FormatTerraformLockAsArgs(lockCheck bool, lockTimeout string) []string
- func FormatTerraformPlanFileAsArg(commandType string, outPath string) []string
- func FormatTerraformPluginDirAsArgs(pluginDir string) []string
- func FormatTerraformVarsAsArgs(vars map[string]any) []string
- func Get(t testing.TestingT, options *Options) stringdeprecated
- func GetAllVariablesFromVarFile(t testing.TestingT, fileName string, out any)
- func GetAllVariablesFromVarFileE(t testing.TestingT, fileName string, out any) error
- func GetContext(t testing.TestingT, ctx context.Context, options *Options) string
- func GetContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func GetE(t testing.TestingT, options *Options) (string, error)deprecated
- func GetExitCodeForTerraformCommand(t testing.TestingT, additionalOptions *Options, args ...string) intdeprecated
- func GetExitCodeForTerraformCommandContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) int
- func GetExitCodeForTerraformCommandContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) (int, error)
- func GetExitCodeForTerraformCommandE(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (int, error)deprecated
- func GetVariableAsListFromVarFile(t testing.TestingT, fileName string, key string) []string
- func GetVariableAsListFromVarFileE(t testing.TestingT, fileName string, key string) ([]string, error)
- func GetVariableAsMapFromVarFile(t testing.TestingT, fileName string, key string) map[string]string
- func GetVariableAsMapFromVarFileE(t testing.TestingT, fileName string, key string) (map[string]string, error)
- func GetVariableAsStringFromVarFile(t testing.TestingT, fileName string, key string) string
- func GetVariableAsStringFromVarFileE(t testing.TestingT, fileName string, key string) (string, error)
- func HCLFileToJSONFile(hclPath, jsonOutPath string) error
- func Init(t testing.TestingT, options *Options) stringdeprecated
- func InitAndApply(t testing.TestingT, options *Options) stringdeprecated
- func InitAndApplyAndIdempotent(t testing.TestingT, options *Options) stringdeprecated
- func InitAndApplyAndIdempotentContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndApplyAndIdempotentContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndApplyAndIdempotentE(t testing.TestingT, options *Options) (string, error)deprecated
- func InitAndApplyContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndApplyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndApplyE(t testing.TestingT, options *Options) (string, error)deprecated
- func InitAndPlan(t testing.TestingT, options *Options) stringdeprecated
- func InitAndPlanAndShow(t testing.TestingT, options *Options) stringdeprecated
- func InitAndPlanAndShowContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndPlanAndShowContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndPlanAndShowE(t testing.TestingT, options *Options) (string, error)deprecated
- func InitAndPlanContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndPlanContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndPlanE(t testing.TestingT, options *Options) (string, error)deprecated
- func InitAndPlanWithExitCode(t testing.TestingT, options *Options) intdeprecated
- func InitAndPlanWithExitCodeContext(t testing.TestingT, ctx context.Context, options *Options) int
- func InitAndPlanWithExitCodeContextE(t testing.TestingT, ctx context.Context, options *Options) (int, error)
- func InitAndPlanWithExitCodeE(t testing.TestingT, options *Options) (int, error)deprecated
- func InitAndValidate(t testing.TestingT, options *Options) stringdeprecated
- func InitAndValidateContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndValidateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndValidateE(t testing.TestingT, options *Options) (string, error)deprecated
- func InitContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitE(t testing.TestingT, options *Options) (string, error)deprecated
- func IsExistingWorkspace(out string, name string) bool
- func OPAEval(t testing.TestingT, tfOptions *Options, opaEvalOptions *opa.EvalOptions, ...)deprecated
- func OPAEvalContext(t testing.TestingT, ctx context.Context, tfOptions *Options, ...)
- func OPAEvalContextE(t testing.TestingT, ctx context.Context, tfOptions *Options, ...) error
- func OPAEvalE(t testing.TestingT, tfOptions *Options, opaEvalOptions *opa.EvalOptions, ...) errordeprecated
- func Output(t testing.TestingT, options *Options, key string) stringdeprecated
- func OutputAll(t testing.TestingT, options *Options) map[string]anydeprecated
- func OutputAllContext(t testing.TestingT, ctx context.Context, options *Options) map[string]any
- func OutputAllContextE(t testing.TestingT, ctx context.Context, options *Options) (map[string]any, error)
- func OutputAllE(t testing.TestingT, options *Options) (map[string]any, error)deprecated
- func OutputContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
- func OutputContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
- func OutputE(t testing.TestingT, options *Options, key string) (string, error)deprecated
- func OutputForKeys(t testing.TestingT, options *Options, keys []string) map[string]anydeprecated
- func OutputForKeysContext(t testing.TestingT, ctx context.Context, options *Options, keys []string) map[string]any
- func OutputForKeysContextE(t testing.TestingT, ctx context.Context, options *Options, keys []string) (map[string]any, error)
- func OutputForKeysE(t testing.TestingT, options *Options, keys []string) (map[string]any, error)deprecated
- func OutputJSON(t testing.TestingT, options *Options, key string) stringdeprecated
- func OutputJSONContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
- func OutputJSONContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
- func OutputJSONE(t testing.TestingT, options *Options, key string) (string, error)deprecated
- func OutputJson(t testing.TestingT, options *Options, key string) stringdeprecated
- func OutputJsonE(t testing.TestingT, options *Options, key string) (string, error)deprecated
- func OutputList(t testing.TestingT, options *Options, key string) []stringdeprecated
- func OutputListContext(t testing.TestingT, ctx context.Context, options *Options, key string) []string
- func OutputListContextE(t testing.TestingT, ctx context.Context, options *Options, key string) ([]string, error)
- func OutputListE(t testing.TestingT, options *Options, key string) ([]string, error)deprecated
- func OutputListOfObjects(t testing.TestingT, options *Options, key string) []map[string]anydeprecated
- func OutputListOfObjectsContext(t testing.TestingT, ctx context.Context, options *Options, key string) []map[string]any
- func OutputListOfObjectsContextE(t testing.TestingT, ctx context.Context, options *Options, key string) ([]map[string]any, error)
- func OutputListOfObjectsE(t testing.TestingT, options *Options, key string) ([]map[string]any, error)deprecated
- func OutputMap(t testing.TestingT, options *Options, key string) map[string]stringdeprecated
- func OutputMapContext(t testing.TestingT, ctx context.Context, options *Options, key string) map[string]string
- func OutputMapContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (map[string]string, error)
- func OutputMapE(t testing.TestingT, options *Options, key string) (map[string]string, error)deprecated
- func OutputMapOfObjects(t testing.TestingT, options *Options, key string) map[string]anydeprecated
- func OutputMapOfObjectsContext(t testing.TestingT, ctx context.Context, options *Options, key string) map[string]any
- func OutputMapOfObjectsContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (map[string]any, error)
- func OutputMapOfObjectsE(t testing.TestingT, options *Options, key string) (map[string]any, error)deprecated
- func OutputRequired(t testing.TestingT, options *Options, key string) stringdeprecated
- func OutputRequiredContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
- func OutputRequiredContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
- func OutputRequiredE(t testing.TestingT, options *Options, key string) (string, error)deprecated
- func OutputStruct(t testing.TestingT, options *Options, key string, v any)deprecated
- func OutputStructContext(t testing.TestingT, ctx context.Context, options *Options, key string, v any)
- func OutputStructContextE(t testing.TestingT, ctx context.Context, options *Options, key string, v any) error
- func OutputStructE(t testing.TestingT, options *Options, key string, v any) errordeprecated
- func Plan(t testing.TestingT, options *Options) stringdeprecated
- func PlanContext(t testing.TestingT, ctx context.Context, options *Options) string
- func PlanContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func PlanE(t testing.TestingT, options *Options) (string, error)deprecated
- func PlanExitCode(t testing.TestingT, options *Options) intdeprecated
- func PlanExitCodeContext(t testing.TestingT, ctx context.Context, options *Options) int
- func PlanExitCodeContextE(t testing.TestingT, ctx context.Context, options *Options) (int, error)
- func PlanExitCodeE(t testing.TestingT, options *Options) (int, error)deprecated
- func RequirePlannedValuesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
- func RequireResourceChangesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
- func RunTerraformCommand(t testing.TestingT, additionalOptions *Options, args ...string) stringdeprecated
- func RunTerraformCommandAndGetStdOutErrCode(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (stdout string, stderr string, exit int)deprecated
- func RunTerraformCommandAndGetStdOutErrCodeContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) (stdout string, stderr string, exit int)
- func RunTerraformCommandAndGetStdOutErrCodeContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) (stdout string, stderr string, exit int, err error)
- func RunTerraformCommandAndGetStdOutErrCodeE(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (stdout string, stderr string, exit int, err error)deprecated
- func RunTerraformCommandAndGetStdout(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) stringdeprecated
- func RunTerraformCommandAndGetStdoutContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) string
- func RunTerraformCommandAndGetStdoutContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) (string, error)
- func RunTerraformCommandAndGetStdoutE(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (string, error)deprecated
- func RunTerraformCommandContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) string
- func RunTerraformCommandContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, ...) (string, error)
- func RunTerraformCommandE(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (string, error)deprecated
- func Show(t testing.TestingT, options *Options) stringdeprecated
- func ShowContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ShowContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ShowE(t testing.TestingT, options *Options) (string, error)deprecated
- func Validate(t testing.TestingT, options *Options) stringdeprecated
- func ValidateContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ValidateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ValidateE(t testing.TestingT, options *Options) (string, error)deprecated
- func WorkspaceDelete(t testing.TestingT, options *Options, name string) stringdeprecated
- func WorkspaceDeleteContext(t testing.TestingT, ctx context.Context, options *Options, name string) string
- func WorkspaceDeleteContextE(t testing.TestingT, ctx context.Context, options *Options, name string) (string, error)
- func WorkspaceDeleteE(t testing.TestingT, options *Options, name string) (string, error)deprecated
- func WorkspaceSelectOrNew(t testing.TestingT, options *Options, name string) stringdeprecated
- func WorkspaceSelectOrNewContext(t testing.TestingT, ctx context.Context, options *Options, name string) string
- func WorkspaceSelectOrNewContextE(t testing.TestingT, ctx context.Context, options *Options, name string) (string, error)
- func WorkspaceSelectOrNewE(t testing.TestingT, options *Options, name string) (string, error)deprecated
- type CtyJSONOutput
- type CtyJsonOutputdeprecated
- type EmptyOutput
- type ExtraArgs
- type InputFileKeyNotFound
- type Options
- type OutputKeyNotFound
- type OutputValueNotList
- type OutputValueNotMap
- type PanicWhileParsingVarFile
- type PlanStruct
- func InitAndPlanAndShowWithStruct(t testing.TestingT, options *Options) *PlanStructdeprecated
- func InitAndPlanAndShowWithStructContext(t testing.TestingT, ctx context.Context, options *Options) *PlanStruct
- func InitAndPlanAndShowWithStructContextE(t testing.TestingT, ctx context.Context, options *Options) (*PlanStruct, error)
- func InitAndPlanAndShowWithStructE(t testing.TestingT, options *Options) (*PlanStruct, error)deprecated
- func InitAndPlanAndShowWithStructNoLogTempPlanFile(t testing.TestingT, options *Options) *PlanStructdeprecated
- func InitAndPlanAndShowWithStructNoLogTempPlanFileContext(t testing.TestingT, ctx context.Context, options *Options) *PlanStruct
- func ParsePlanJSON(jsonStr string) (*PlanStruct, error)
- func ShowWithStruct(t testing.TestingT, options *Options) *PlanStructdeprecated
- func ShowWithStructContext(t testing.TestingT, ctx context.Context, options *Options) *PlanStruct
- func ShowWithStructContextE(t testing.TestingT, ctx context.Context, options *Options) (*PlanStruct, error)
- func ShowWithStructE(t testing.TestingT, options *Options) (*PlanStruct, error)deprecated
- type ResourceCount
- type UnexpectedOutputType
- type UnsupportedDefaultWorkspaceDeletion
- type Var
- type VarFileNotFound
- type WorkspaceDoesNotExist
Constants ¶
const ( // TofuDefaultPath command to run tofu TofuDefaultPath = "tofu" // TerraformDefaultPath to run terraform TerraformDefaultPath = "terraform" )
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 GetResourceCountErrMessage = "can't parse Terraform output"
GetResourceCountErrMessage is the error message returned when terraform output cannot be parsed.
const TerraformPlanChangesPresentExitCode = 2
TerraformPlanChangesPresentExitCode is the exit code returned by terraform plan detailed exitcode when changes are present
Variables ¶
var DefaultExecutable = defaultTerraformExecutable()
DefaultExecutable is the default terraform executable to use. It is set to "terraform" if the terraform binary is available, otherwise it falls back to "tofu".
var (
DefaultRetryableTerraformErrors = map[string]string{
".*read: connection reset by peer.*": "Failed to reach helm charts repository.",
".*transport is closing.*": "Failed to reach Kubernetes API.",
".*unable to verify signature.*": "Failed to retrieve plugin due to transient network error.",
".*unable to verify checksum.*": "Failed to retrieve plugin due to transient network error.",
".*no provider exists with the given name.*": "Failed to retrieve plugin due to transient network error.",
".*registry service is unreachable.*": "Failed to retrieve plugin due to transient network error.",
".*Error installing provider.*": "Failed to retrieve plugin due to transient network error.",
".*Failed to query available provider packages.*": "Failed to retrieve plugin due to transient network error.",
".*timeout while waiting for plugin to start.*": "Failed to retrieve plugin due to transient network error.",
".*timed out waiting for server handshake.*": "Failed to retrieve plugin due to transient network error.",
"could not query provider registry for": "Failed to retrieve plugin due to transient network error.",
".*Provider produced inconsistent result after apply.*": "Provider eventual consistency error.",
}
)
DefaultRetryableTerraformErrors is the default set of error patterns that [Options.RetryableTerraformErrors] will be initialized with. The keys are regular expressions matched against Terraform output, and the values are human-friendly messages displayed when the matching error triggers a retry.
var ( // PlanFilePathRequired is returned when PlanFilePath is not set on Options but is required by the called function. PlanFilePathRequired = errors.New("you must set PlanFilePath on options struct to use this function") //nolint:staticcheck // preserving existing public variable name )
var TerraformCommandsWithLockSupport = []string{
"plan",
"apply",
"destroy",
"init",
"refresh",
"taint",
"untaint",
"import",
}
TerraformCommandsWithLockSupport is a list of all the Terraform commands that can obtain locks on Terraform state
var TerraformCommandsWithPlanFileSupport = []string{
"plan",
"apply",
"show",
"graph",
}
TerraformCommandsWithPlanFileSupport is a list of all the Terraform commands that support interacting with plan files.
Functions ¶
func Apply
deprecated
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.
Deprecated: Use ApplyContext instead.
func ApplyAndIdempotent
deprecated
added in
v0.28.5
ApplyAndIdempotent runs terraform apply with the given options and return stdout/stderr from the apply command. It then runs plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
Deprecated: Use ApplyAndIdempotentContext instead.
func ApplyAndIdempotentContext ¶ added in v1.0.0
ApplyAndIdempotentContext runs terraform apply with the given options and returns stdout/stderr from the apply command. It then runs plan again and will fail the test if plan requires additional changes. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func ApplyAndIdempotentContextE ¶ added in v1.0.0
func ApplyAndIdempotentContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
ApplyAndIdempotentContextE runs terraform apply with the given options and returns stdout/stderr from the apply command. It then runs plan again and will fail the test if plan requires additional changes. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func ApplyAndIdempotentE
deprecated
added in
v0.28.5
ApplyAndIdempotentE runs terraform apply with the given options and return stdout/stderr from the apply command. It then runs plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
Deprecated: Use ApplyAndIdempotentContextE instead.
func ApplyContext ¶ added in v1.0.0
ApplyContext runs terraform apply with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func ApplyContextE ¶ added in v1.0.0
ApplyContextE runs terraform apply with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. 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
deprecated
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.
Deprecated: Use ApplyContextE instead.
func AssertPlannedValuesMapKeyExists ¶ added in v0.32.19
func AssertPlannedValuesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
AssertPlannedValuesMapKeyExists checks if the given key exists in the map, failing the test if it does not.
func AssertResourceChangesMapKeyExists ¶ added in v0.32.19
func AssertResourceChangesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
AssertResourceChangesMapKeyExists checks if the given key exists in the map, failing the test if it does not.
func DestroyContext ¶ added in v1.0.0
DestroyContext runs terraform destroy with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func DestroyContextE ¶ added in v1.0.0
DestroyContextE runs terraform destroy with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
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 ¶ added in v0.13.27
FormatTerraformArgs will format multiple args with the arg name (e.g. "-var-file", []string{"foo.tfvars", "bar.tfvars", "baz.tfvars.json"}) returns "-var-file foo.tfvars -var-file bar.tfvars -var-file baz.tfvars.json"
func FormatTerraformBackendConfigAsArgs ¶ added in v0.9.13
FormatTerraformBackendConfigAsArgs formats the given variables as backend config args for Terraform (e.g. of the format -backend-config=key=value).
func FormatTerraformLockAsArgs ¶ added in v0.23.1
FormatTerraformLockAsArgs formats the lock and lock-timeout variables -lock, -lock-timeout
func FormatTerraformPlanFileAsArg ¶ added in v0.30.16
FormatTerraformPlanFileAsArg formats the out variable as a command-line arg for Terraform (e.g. of the format -out=/some/path/to/plan.out or /some/path/to/plan.out). Only plan supports passing in the plan file as -out; the other commands expect it as the first positional argument. This returns an empty string if outPath is empty string.
func FormatTerraformPluginDirAsArgs ¶ added in v0.32.13
FormatTerraformPluginDirAsArgs formats the plugin-dir variable -plugin-dir
func FormatTerraformVarsAsArgs ¶
FormatTerraformVarsAsArgs formats the given variables as command-line args for Terraform (e.g. of the format -var key=value).
func GetAllVariablesFromVarFile ¶ added in v0.32.6
GetAllVariablesFromVarFile Parses all data from a provided input file found ind in VarFile and stores the result in the value pointed to by out.
func GetAllVariablesFromVarFileE ¶ added in v0.32.6
GetAllVariablesFromVarFileE Parses all data from a provided input file found ind in VarFile and stores the result in the value pointed to by out. Returns an error if the specified file does not exist, the specified file is not readable, or the specified file cannot be decoded from HCL.
func GetContext ¶ added in v1.0.0
GetContext calls terraform get and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func GetContextE ¶ added in v1.0.0
GetContextE calls terraform get and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func GetExitCodeForTerraformCommand
deprecated
added in
v0.10.4
func GetExitCodeForTerraformCommandContext ¶ added in v1.0.0
func GetExitCodeForTerraformCommandContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, args ...string) int
GetExitCodeForTerraformCommandContext runs terraform with the given arguments and options and returns exit code.
func GetExitCodeForTerraformCommandContextE ¶ added in v1.0.0
func GetExitCodeForTerraformCommandContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, additionalArgs ...string) (int, error)
GetExitCodeForTerraformCommandContextE runs terraform with the given arguments and options and returns exit code.
func GetExitCodeForTerraformCommandE
deprecated
added in
v0.10.4
func GetVariableAsListFromVarFile ¶ added in v0.32.6
GetVariableAsListFromVarFile Gets the string list representation of a variable from a provided input file found in VarFile Note that this returns a list of strings. For lists containing complex types, use GetAllVariablesFromVarFile.
func GetVariableAsListFromVarFileE ¶ added in v0.32.6
func GetVariableAsListFromVarFileE(t testing.TestingT, fileName string, key string) ([]string, error)
GetVariableAsListFromVarFileE Gets the string list representation of a variable from a provided input file found in VarFile Note that this returns a list of strings. For lists containing complex types, use GetAllVariablesFromVarFile. Will return error if GetAllVariablesFromVarFileE returns an error, the key provided does not exist, or the value associated with the key is not a list
func GetVariableAsMapFromVarFile ¶ added in v0.32.6
GetVariableAsMapFromVarFile Gets the map representation of a variable from a provided input file found in VarFile Note that this returns a map of strings. For maps containing complex types, use GetAllVariablesFromVarFile.
func GetVariableAsMapFromVarFileE ¶ added in v0.32.6
func GetVariableAsMapFromVarFileE(t testing.TestingT, fileName string, key string) (map[string]string, error)
GetVariableAsMapFromVarFileE Gets the map representation of a variable from a provided input file found in VarFile. Note that this returns a map of strings. For maps containing complex types, use GetAllVariablesFromVarFile Returns an error if GetAllVariablesFromVarFileE returns an error, the key provided does not exist, or the value associated with the key is not a map
func GetVariableAsStringFromVarFile ¶ added in v0.32.6
GetVariableAsStringFromVarFile Gets the string representation of a variable from a provided input file found in VarFile For list or map, use GetVariableAsListFromVarFile or GetVariableAsMapFromVarFile, respectively.
func GetVariableAsStringFromVarFileE ¶ added in v0.32.6
func GetVariableAsStringFromVarFileE(t testing.TestingT, fileName string, key string) (string, error)
GetVariableAsStringFromVarFileE Gets the string representation of a variable from a provided input file found in VarFile Will return an error if GetAllVariablesFromVarFileE returns an error or the key provided does not exist in the file. For list or map, use GetVariableAsListFromVarFile or GetVariableAsMapFromVarFile, respectively.
func HCLFileToJSONFile ¶ added in v0.38.1
HCLFileToJSONFile is a function that takes a path containing HCL code, and converts it to JSON representation and writes out the contents to the given path.
func InitAndApply
deprecated
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.
Deprecated: Use InitAndApplyContext instead.
func InitAndApplyAndIdempotent
deprecated
added in
v0.28.5
InitAndApplyAndIdempotent runs terraform init and apply with the given options and return stdout/stderr from the apply command. It then runs plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
Deprecated: Use InitAndApplyAndIdempotentContext instead.
func InitAndApplyAndIdempotentContext ¶ added in v1.0.0
func InitAndApplyAndIdempotentContext(t testing.TestingT, ctx context.Context, options *Options) string
InitAndApplyAndIdempotentContext runs terraform init, apply, and then plan with the given options and returns stdout/stderr from the apply command. It will fail the test if plan requires additional changes after the apply. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func InitAndApplyAndIdempotentContextE ¶ added in v1.0.0
func InitAndApplyAndIdempotentContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
InitAndApplyAndIdempotentContextE runs terraform init, apply, and then plan with the given options and returns stdout/stderr from the apply command. It will fail the test if plan requires additional changes after the apply. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func InitAndApplyAndIdempotentE
deprecated
added in
v0.28.5
InitAndApplyAndIdempotentE runs terraform init and apply with the given options and return stdout/stderr from the apply command. It then runs plan again and will fail the test if plan requires additional changes. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
Deprecated: Use InitAndApplyAndIdempotentContextE instead.
func InitAndApplyContext ¶ added in v1.0.0
InitAndApplyContext runs terraform init and apply with the given options and returns stdout/stderr from the apply command. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func InitAndApplyContextE ¶ added in v1.0.0
func InitAndApplyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
InitAndApplyContextE runs terraform init and apply with the given options and returns stdout/stderr from the apply command. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. 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
deprecated
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.
Deprecated: Use InitAndApplyContextE instead.
func InitAndPlan
deprecated
added in
v0.10.4
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.
Deprecated: Use InitAndPlanContext instead.
func InitAndPlanAndShow
deprecated
added in
v0.30.16
InitAndPlanAndShow runs terraform init, then terraform plan, and then terraform show with the given options, and returns the json output of the plan file. This will fail the test if there is an error in the command.
Deprecated: Use InitAndPlanAndShowContext instead.
func InitAndPlanAndShowContext ¶ added in v1.0.0
InitAndPlanAndShowContext runs terraform init, then terraform plan, and then terraform show with the given options, and returns the json output of the plan file. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func InitAndPlanAndShowContextE ¶ added in v1.0.0
func InitAndPlanAndShowContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
InitAndPlanAndShowContextE runs terraform init, then terraform plan, and then terraform show with the given options, and returns the json output of the plan file. The context argument can be used for cancellation or timeout control.
func InitAndPlanAndShowE
deprecated
added in
v0.30.16
func InitAndPlanContext ¶ added in v1.0.0
InitAndPlanContext runs terraform init and plan with the given options and returns stdout/stderr from the plan command. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func InitAndPlanContextE ¶ added in v1.0.0
InitAndPlanContextE runs terraform init and plan with the given options and returns stdout/stderr from the plan command. The context argument can be used for cancellation or timeout control.
func InitAndPlanE
deprecated
added in
v0.10.4
func InitAndPlanWithExitCode
deprecated
added in
v0.17.0
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.
Deprecated: Use InitAndPlanWithExitCodeContext instead.
func InitAndPlanWithExitCodeContext ¶ added in v1.0.0
InitAndPlanWithExitCodeContext runs terraform init and plan with the given options and returns the exitcode for the plan command. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func InitAndPlanWithExitCodeContextE ¶ added in v1.0.0
func InitAndPlanWithExitCodeContextE(t testing.TestingT, ctx context.Context, options *Options) (int, error)
InitAndPlanWithExitCodeContextE runs terraform init and plan with the given options and returns the exitcode for the plan command. The context argument can be used for cancellation or timeout control.
func InitAndPlanWithExitCodeE
deprecated
added in
v0.17.0
func InitAndValidate
deprecated
added in
v0.32.23
InitAndValidate runs terraform init and validate with the given options and returns stdout/stderr from the validate command. This will fail the test if there is an error in the command.
Deprecated: Use InitAndValidateContext instead.
func InitAndValidateContext ¶ added in v1.0.0
InitAndValidateContext runs terraform init and validate with the given options and returns stdout/stderr from the validate command. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This will fail the test if there is an error in the command.
func InitAndValidateContextE ¶ added in v1.0.0
func InitAndValidateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
InitAndValidateContextE runs terraform init and validate with the given options and returns stdout/stderr from the validate command. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func InitAndValidateE
deprecated
added in
v0.32.23
func InitContext ¶ added in v1.0.0
InitContext calls terraform init with the given options and returns stdout/stderr. The context argument can be used for cancellation or timeout control.
func InitContextE ¶ added in v1.0.0
InitContextE calls terraform init with the given options and returns stdout/stderr. The context argument can be used for cancellation or timeout control.
func IsExistingWorkspace ¶ added in v1.0.0
IsExistingWorkspace checks if a workspace with the given name exists in the terraform workspace list output.
func OPAEval
deprecated
added in
v0.38.1
func OPAEval( t testing.TestingT, tfOptions *Options, opaEvalOptions *opa.EvalOptions, resultQuery string, )
OPAEval runs `opa eval` with the given option on the terraform files identified in the TerraformDir directory of the Options struct. Note that since OPA does not natively support parsing HCL code, we first convert all the files to JSON prior to passing it through OPA. This function fails the test if there is an error.
Deprecated: Use OPAEvalContext instead.
func OPAEvalContext ¶ added in v1.0.0
func OPAEvalContext( t testing.TestingT, ctx context.Context, tfOptions *Options, opaEvalOptions *opa.EvalOptions, resultQuery string, )
OPAEvalContext runs `opa eval` with the given options on the terraform files identified in the TerraformDir directory of the Options struct. Note that since OPA does not natively support parsing HCL code, we first convert all the files to JSON prior to passing it through OPA. The context argument can be used for cancellation or timeout control. This function fails the test if there is an error.
func OPAEvalContextE ¶ added in v1.0.0
func OPAEvalContextE( t testing.TestingT, ctx context.Context, tfOptions *Options, opaEvalOptions *opa.EvalOptions, resultQuery string, ) error
OPAEvalContextE runs `opa eval` with the given options on the terraform files identified in the TerraformDir directory of the Options struct. Note that since OPA does not natively support parsing HCL code, we first convert all the files to JSON prior to passing it through OPA. The context argument can be used for cancellation or timeout control.
func OPAEvalE
deprecated
added in
v0.38.1
func OPAEvalE( t testing.TestingT, tfOptions *Options, opaEvalOptions *opa.EvalOptions, resultQuery string, ) error
OPAEvalE runs `opa eval` with the given option on the terraform files identified in the TerraformDir directory of the Options struct. Note that since OPA does not natively support parsing HCL code, we first convert all the files to JSON prior to passing it through OPA.
Deprecated: Use OPAEvalContextE instead.
func Output
deprecated
Output calls terraform output for the given variable and return its string value representation. It only designed to work with primitive terraform types: string, number and bool. Please use OutputStruct for anything else.
Deprecated: Use OutputContext instead.
func OutputAllContext ¶ added in v1.0.0
OutputAllContext calls terraform output and returns all values as a map. If there is an error fetching the output, it fails the test. The context argument can be used for cancellation or timeout control.
func OutputAllContextE ¶ added in v1.0.0
func OutputAllContextE(t testing.TestingT, ctx context.Context, options *Options) (map[string]any, error)
OutputAllContextE calls terraform output and returns all the outputs as a map. The context argument can be used for cancellation or timeout control.
func OutputAllE
deprecated
added in
v0.13.19
func OutputContext ¶ added in v1.0.0
OutputContext calls terraform output for the given variable and returns its string value representation. It is only designed to work with primitive terraform types: string, number and bool. Please use OutputStructContext for anything else. The context argument can be used for cancellation or timeout control.
func OutputContextE ¶ added in v1.0.0
func OutputContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
OutputContextE calls terraform output for the given variable and returns its string value representation. It is only designed to work with primitive terraform types: string, number and bool. Please use OutputStructContextE for anything else. The context argument can be used for cancellation or timeout control.
func OutputE
deprecated
OutputE calls terraform output for the given variable and return its string value representation. It only designed to work with primitive terraform types: string, number and bool. Please use OutputStructE for anything else.
Deprecated: Use OutputContextE instead.
func OutputForKeys
deprecated
added in
v0.13.19
func OutputForKeysContext ¶ added in v1.0.0
func OutputForKeysContext(t testing.TestingT, ctx context.Context, options *Options, keys []string) map[string]any
OutputForKeysContext calls terraform output for the given key list and returns values as a map. If keys are not found in the output, it fails the test. The context argument can be used for cancellation or timeout control.
func OutputForKeysContextE ¶ added in v1.0.0
func OutputForKeysContextE(t testing.TestingT, ctx context.Context, options *Options, keys []string) (map[string]any, error)
OutputForKeysContextE calls terraform output for the given key list and returns values as a map. The returned values are of type any and need to be type casted as necessary. The context argument can be used for cancellation or timeout control.
func OutputForKeysE
deprecated
added in
v0.13.19
OutputForKeysE calls terraform output for the given key list and returns values as a map. The returned values are of type any and need to be type casted as necessary. Refer to output_test.go
Deprecated: Use OutputForKeysContextE instead.
func OutputJSON
deprecated
added in
v1.0.0
func OutputJSONContext ¶ added in v1.0.0
func OutputJSONContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
OutputJSONContext calls terraform output for the given variable and returns the result as a JSON string. If key is an empty string, it will return all the output variables. The context argument can be used for cancellation or timeout control.
func OutputJSONContextE ¶ added in v1.0.0
func OutputJSONContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
OutputJSONContextE calls terraform output for the given variable and returns the result as a JSON string. If key is an empty string, it will return all the output variables. The context argument can be used for cancellation or timeout control.
func OutputJSONE
deprecated
added in
v1.0.0
func OutputJson
deprecated
added in
v0.31.1
func OutputJsonE
deprecated
added in
v0.31.1
func OutputList
deprecated
added in
v0.13.1
func OutputListContext ¶ added in v1.0.0
func OutputListContext(t testing.TestingT, ctx context.Context, options *Options, key string) []string
OutputListContext 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. The context argument can be used for cancellation or timeout control.
func OutputListContextE ¶ added in v1.0.0
func OutputListContextE(t testing.TestingT, ctx context.Context, options *Options, key string) ([]string, error)
OutputListContextE 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. The context argument can be used for cancellation or timeout control.
func OutputListE
deprecated
added in
v0.13.1
func OutputListOfObjects
deprecated
added in
v0.28.2
OutputListOfObjects calls terraform output for the given variable and returns its value as a list of maps/lists. If the output value is not a list of maps/lists, then it fails the test.
Deprecated: Use OutputListOfObjectsContext instead.
func OutputListOfObjectsContext ¶ added in v1.0.0
func OutputListOfObjectsContext(t testing.TestingT, ctx context.Context, options *Options, key string) []map[string]any
OutputListOfObjectsContext calls terraform output for the given variable and returns its value as a list of maps/lists. If the output value is not a list of maps/lists, then it fails the test. The context argument can be used for cancellation or timeout control.
func OutputListOfObjectsContextE ¶ added in v1.0.0
func OutputListOfObjectsContextE(t testing.TestingT, ctx context.Context, options *Options, key string) ([]map[string]any, error)
OutputListOfObjectsContextE calls terraform output for the given variable and returns its value as a list of maps/lists. Also returns an error object if an error was generated. If the output value is not a list of maps/lists, then it returns an error. The context argument can be used for cancellation or timeout control.
func OutputListOfObjectsE
deprecated
added in
v0.28.2
func OutputListOfObjectsE(t testing.TestingT, options *Options, key string) ([]map[string]any, error)
OutputListOfObjectsE calls terraform output for the given variable and returns its value as a list of maps/lists. Also returns an error object if an error was generated. If the output value is not a list of maps/lists, then it fails the test.
Deprecated: Use OutputListOfObjectsContextE instead.
func OutputMap
deprecated
added in
v0.13.6
func OutputMapContext ¶ added in v1.0.0
func OutputMapContext(t testing.TestingT, ctx context.Context, options *Options, key string) map[string]string
OutputMapContext 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. The context argument can be used for cancellation or timeout control.
func OutputMapContextE ¶ added in v1.0.0
func OutputMapContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (map[string]string, error)
OutputMapContextE 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. The context argument can be used for cancellation or timeout control.
func OutputMapE
deprecated
added in
v0.13.6
func OutputMapOfObjects
deprecated
added in
v0.28.2
OutputMapOfObjects calls terraform output for the given variable and returns its value as a map of lists/maps. If the output value is not a map of lists/maps, then it fails the test.
Deprecated: Use OutputMapOfObjectsContext instead.
func OutputMapOfObjectsContext ¶ added in v1.0.0
func OutputMapOfObjectsContext(t testing.TestingT, ctx context.Context, options *Options, key string) map[string]any
OutputMapOfObjectsContext calls terraform output for the given variable and returns its value as a map of lists/maps. If the output value is not a map of lists/maps, then it fails the test. The context argument can be used for cancellation or timeout control.
func OutputMapOfObjectsContextE ¶ added in v1.0.0
func OutputMapOfObjectsContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (map[string]any, error)
OutputMapOfObjectsContextE calls terraform output for the given variable and returns its value as a map of lists/maps. Also returns an error object if an error was generated. If the output value is not a map of lists/maps, then it returns an error. The context argument can be used for cancellation or timeout control.
func OutputMapOfObjectsE
deprecated
added in
v0.28.2
OutputMapOfObjectsE calls terraform output for the given variable and returns its value as a map of lists/maps. Also returns an error object if an error was generated. If the output value is not a map of lists/maps, then it fails the test.
Deprecated: Use OutputMapOfObjectsContextE instead.
func OutputRequired
deprecated
func OutputRequiredContext ¶ added in v1.0.0
func OutputRequiredContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
OutputRequiredContext calls terraform output for the given variable and returns its value. If the value is empty, the test is failed. The context argument can be used for cancellation or timeout control.
func OutputRequiredContextE ¶ added in v1.0.0
func OutputRequiredContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
OutputRequiredContextE calls terraform output for the given variable and returns its value. If the value is empty, an error is returned. The context argument can be used for cancellation or timeout control.
func OutputRequiredE
deprecated
func OutputStruct
deprecated
added in
v0.28.8
OutputStruct calls terraform output for the given variable and stores the result in the value pointed to by v. If v is nil or not a pointer, or if the value returned by Terraform is not appropriate for a given target type, it fails the test.
Deprecated: Use OutputStructContext instead.
func OutputStructContext ¶ added in v1.0.0
func OutputStructContext(t testing.TestingT, ctx context.Context, options *Options, key string, v any)
OutputStructContext calls terraform output for the given variable and stores the result in the value pointed to by v. If v is nil or not a pointer, or if the value returned by Terraform is not appropriate for a given target type, it fails the test. The context argument can be used for cancellation or timeout control.
func OutputStructContextE ¶ added in v1.0.0
func OutputStructContextE(t testing.TestingT, ctx context.Context, options *Options, key string, v any) error
OutputStructContextE calls terraform output for the given variable and stores the result in the value pointed to by v. If v is nil or not a pointer, or if the value returned by Terraform is not appropriate for a given target type, it returns an error. The context argument can be used for cancellation or timeout control.
func OutputStructE
deprecated
added in
v0.28.8
OutputStructE calls terraform output for the given variable and stores the result in the value pointed to by v. If v is nil or not a pointer, or if the value returned by Terraform is not appropriate for a given target type, it returns an error.
Deprecated: Use OutputStructContextE instead.
func PlanContext ¶ added in v1.0.0
PlanContext runs terraform plan with the given options and returns stdout/stderr. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func PlanContextE ¶ added in v1.0.0
PlanContextE runs terraform plan with the given options and returns stdout/stderr. The context argument can be used for cancellation or timeout control.
func PlanExitCode
deprecated
added in
v0.10.4
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.
Deprecated: Use PlanExitCodeContext instead.
func PlanExitCodeContext ¶ added in v1.0.0
PlanExitCodeContext runs terraform plan with the given options and returns the detailed exitcode. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func PlanExitCodeContextE ¶ added in v1.0.0
PlanExitCodeContextE runs terraform plan with the given options and returns the detailed exitcode. The context argument can be used for cancellation or timeout control.
func PlanExitCodeE
deprecated
added in
v0.10.4
func RequirePlannedValuesMapKeyExists ¶ added in v0.32.19
func RequirePlannedValuesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
RequirePlannedValuesMapKeyExists checks if the given key exists in the map, failing and halting the test if it does not.
func RequireResourceChangesMapKeyExists ¶ added in v0.32.19
func RequireResourceChangesMapKeyExists(t testing.TestingT, plan *PlanStruct, keyQuery string)
RequireResourceChangesMapKeyExists checks if the given key exists in the map, failing the test if it does not.
func RunTerraformCommand
deprecated
added in
v0.9.2
func RunTerraformCommandAndGetStdOutErrCode
deprecated
added in
v0.49.0
func RunTerraformCommandAndGetStdOutErrCode(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (stdout string, stderr string, exit int)
RunTerraformCommandAndGetStdOutErrCode runs terraform with the given arguments and options and returns its stdout, stderr, and exitcode.
Deprecated: Use RunTerraformCommandAndGetStdOutErrCodeContext instead.
func RunTerraformCommandAndGetStdOutErrCodeContext ¶ added in v1.0.0
func RunTerraformCommandAndGetStdOutErrCodeContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, additionalArgs ...string) (stdout string, stderr string, exit int)
RunTerraformCommandAndGetStdOutErrCodeContext runs terraform with the given arguments and options and returns its stdout, stderr, and exitcode.
func RunTerraformCommandAndGetStdOutErrCodeContextE ¶ added in v1.0.0
func RunTerraformCommandAndGetStdOutErrCodeContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, additionalArgs ...string) (stdout string, stderr string, exit int, err error)
RunTerraformCommandAndGetStdOutErrCodeContextE runs terraform with the given arguments and options and returns its stdout, stderr, and exitcode.
func RunTerraformCommandAndGetStdOutErrCodeE
deprecated
added in
v0.49.0
func RunTerraformCommandAndGetStdOutErrCodeE(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (stdout string, stderr string, exit int, err error)
RunTerraformCommandAndGetStdOutErrCodeE runs terraform with the given arguments and options and returns its stdout, stderr, and exitcode.
Deprecated: Use RunTerraformCommandAndGetStdOutErrCodeContextE instead.
func RunTerraformCommandAndGetStdout
deprecated
added in
v0.49.0
func RunTerraformCommandAndGetStdout(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) string
RunTerraformCommandAndGetStdout runs terraform with the given arguments and options and returns solely its stdout (but not stderr).
Deprecated: Use RunTerraformCommandAndGetStdoutContext instead.
func RunTerraformCommandAndGetStdoutContext ¶ added in v1.0.0
func RunTerraformCommandAndGetStdoutContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, additionalArgs ...string) string
RunTerraformCommandAndGetStdoutContext runs terraform with the given arguments and options and returns solely its stdout (but not stderr).
func RunTerraformCommandAndGetStdoutContextE ¶ added in v1.0.0
func RunTerraformCommandAndGetStdoutContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, additionalArgs ...string) (string, error)
RunTerraformCommandAndGetStdoutContextE runs terraform with the given arguments and options and returns solely its stdout (but not stderr).
func RunTerraformCommandAndGetStdoutE
deprecated
added in
v0.17.2
func RunTerraformCommandAndGetStdoutE(t testing.TestingT, additionalOptions *Options, additionalArgs ...string) (string, error)
RunTerraformCommandAndGetStdoutE runs terraform with the given arguments and options and returns solely its stdout (but not stderr).
Deprecated: Use RunTerraformCommandAndGetStdoutContextE instead.
func RunTerraformCommandContext ¶ added in v1.0.0
func RunTerraformCommandContext(t testing.TestingT, ctx context.Context, additionalOptions *Options, args ...string) string
RunTerraformCommandContext runs terraform with the given arguments and options and returns stdout/stderr.
func RunTerraformCommandContextE ¶ added in v1.0.0
func RunTerraformCommandContextE(t testing.TestingT, ctx context.Context, additionalOptions *Options, additionalArgs ...string) (string, error)
RunTerraformCommandContextE runs terraform with the given arguments and options and returns stdout/stderr.
func RunTerraformCommandE
deprecated
added in
v0.9.2
func Show
deprecated
added in
v0.30.16
Show calls terraform show in json mode with the given options and returns stdout from the command. If PlanFilePath is set on the options, this will show the plan file. Otherwise, this will show the current state of the terraform module at options.TerraformDir. This will fail the test if there is an error in the command.
Deprecated: Use ShowContext instead.
func ShowContext ¶ added in v1.0.0
ShowContext calls terraform show in json mode with the given options and returns stdout from the command. If PlanFilePath is set on the options, this will show the plan file. Otherwise, this will show the current state of the terraform module at options.TerraformDir. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func ShowContextE ¶ added in v1.0.0
ShowContextE calls terraform show in json mode with the given options and returns stdout from the command. If PlanFilePath is set on the options, this will show the plan file. Otherwise, this will show the current state of the terraform module at options.TerraformDir. The context argument can be used for cancellation or timeout control.
func ShowE
deprecated
added in
v0.30.16
ShowE calls terraform show in json mode with the given options and returns stdout from the command. If PlanFilePath is set on the options, this will show the plan file. Otherwise, this will show the current state of the terraform module at options.TerraformDir.
Deprecated: Use ShowContextE instead.
func ValidateContext ¶ added in v1.0.0
ValidateContext calls terraform validate and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ValidateContextE ¶ added in v1.0.0
ValidateContextE calls terraform validate and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func WorkspaceDelete
deprecated
added in
v0.32.17
WorkspaceDelete removes the specified terraform workspace with the given options. It returns the name of the current workspace AFTER deletion. If the workspace to delete is the current one, then it tries to switch to the "default" workspace. Deleting the workspace "default" is not supported and only return an empty string (to avoid a fatal error).
Deprecated: Use WorkspaceDeleteContext instead.
func WorkspaceDeleteContext ¶ added in v1.0.0
func WorkspaceDeleteContext(t testing.TestingT, ctx context.Context, options *Options, name string) string
WorkspaceDeleteContext removes the specified terraform workspace with the given options. It returns the name of the current workspace AFTER deletion. If the workspace to delete is the current one, then it tries to switch to the "default" workspace. Deleting the workspace "default" is not supported and only returns an empty string (to avoid a fatal error). The context argument can be used for cancellation or timeout control.
func WorkspaceDeleteContextE ¶ added in v1.0.0
func WorkspaceDeleteContextE(t testing.TestingT, ctx context.Context, options *Options, name string) (string, error)
WorkspaceDeleteContextE removes the specified terraform workspace with the given options. It returns the name of the current workspace AFTER deletion, and the returned error (that can be nil). If the workspace to delete is the current one, then it tries to switch to the "default" workspace. Deleting the workspace "default" is not supported. The context argument can be used for cancellation or timeout control.
func WorkspaceDeleteE
deprecated
added in
v0.32.17
WorkspaceDeleteE removes the specified terraform workspace with the given options. It returns the name of the current workspace AFTER deletion, and the returned error (that can be nil). If the workspace to delete is the current one, then it tries to switch to the "default" workspace. Deleting the workspace "default" is not supported.
Deprecated: Use WorkspaceDeleteContextE instead.
func WorkspaceSelectOrNew
deprecated
added in
v0.12.2
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.
Deprecated: Use WorkspaceSelectOrNewContext instead.
func WorkspaceSelectOrNewContext ¶ added in v1.0.0
func WorkspaceSelectOrNewContext(t testing.TestingT, ctx context.Context, options *Options, name string) string
WorkspaceSelectOrNewContext runs terraform workspace with the given options and the workspace name and returns the 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. The context argument can be used for cancellation or timeout control.
func WorkspaceSelectOrNewContextE ¶ added in v1.0.0
func WorkspaceSelectOrNewContextE(t testing.TestingT, ctx context.Context, options *Options, name string) (string, error)
WorkspaceSelectOrNewContextE runs terraform workspace with the given options and the workspace name and returns the 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. The context argument can be used for cancellation or timeout control.
func WorkspaceSelectOrNewE
deprecated
added in
v0.12.2
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.
Deprecated: Use WorkspaceSelectOrNewContextE instead.
Types ¶
type CtyJSONOutput ¶ added in v1.0.0
CtyJSONOutput captures the output of marshalling a cty value to JSON. When you convert a cty value to JSON, if any of the types are not yet known (i.e., are labeled as DynamicPseudoType), cty's Marshal method will write the type information to a type field and the actual value to a value field. This struct is used to capture that information so when we parse the JSON back into a Go struct, we can pull out just the Value field we need.
type CtyJsonOutput
deprecated
added in
v0.32.8
type CtyJsonOutput = CtyJSONOutput //nolint:revive,staticcheck // preserving deprecated type name
CtyJsonOutput is a backwards-compatible alias for CtyJSONOutput.
Deprecated: Use CtyJSONOutput instead.
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 ExtraArgs ¶ added in v0.49.0
type ExtraArgs struct {
Apply []string
Destroy []string
Get []string
Init []string
Plan []string
Validate []string
WorkspaceDelete []string
WorkspaceSelect []string
WorkspaceNew []string
Output []string
Show []string
}
ExtraArgs holds additional command-line arguments to pass to specific Terraform subcommands. Each field is appended to the corresponding subcommand invocation (e.g. Apply args are appended to `terraform apply`).
type InputFileKeyNotFound ¶ added in v0.32.6
InputFileKeyNotFound occurs when tfvar file does not contain a value for the key specified in the function call
func (InputFileKeyNotFound) Error ¶ added in v0.32.6
func (err InputFileKeyNotFound) Error() string
type Options ¶
type Options struct {
Stdin io.Reader // Optional stdin to pass to Terraform commands
WarningsAsErrors map[string]string // Terraform warning messages that should be treated as errors. The keys are a regexp to match against the warning and the value is what to display to a user if that warning is matched.
Logger *logger.Logger // Set a non-default logger that should be used. See the logger package for more info.
BackendConfig map[string]any // The vars to pass to the terraform init command for extra configuration for the backend. If a var is nil, it will be formated as `--backend-config=var` instead of `--backend-config=var=null`
EnvVars map[string]string // Environment variables to set when running Terraform
// The vars to pass to Terraform commands using the -var option. Note that terraform does not support passing `null`
// as a variable value through the command line. That is, if you use `map[string]any{"foo": nil}` as `Vars`,
// this will translate to the string literal `"null"` being assigned to the variable `foo`. However, nulls in
// lists and maps/objects are supported. E.g., the following var will be set as expected (`{ bar = null }`:
// map[string]any{
// "foo": map[string]any{"bar": nil},
// }
Vars map[string]any
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.
SshAgent *ssh.SSHAgent //nolint:revive,staticcheck // preserving deprecated field name. Overrides local SSH agent with the given in-process agent
TerraformBinary string // Name of the binary that will be used
TerraformDir string // The path to the folder where the Terraform code is defined.
PlanFilePath string // The path to output a plan file to (for the plan command) or read one from (for the apply command)
PluginDir string // The path of downloaded plugins to pass to the terraform init command (-plugin-dir)
LockTimeout string // The lock timeout option to pass to the terraform command with -lock-timeout
ExtraArgs ExtraArgs // Extra arguments passed to Terraform commands
Targets []string // The target resources to pass to the terraform command with -target
MixedVars []Var // Mix of `-var` and `-var-file` in arbritrary order, use `VarInline()` `VarFile()` to set the value.
VarFiles []string // The var file paths to pass to Terraform commands using -var-file option.
TimeBetweenRetries time.Duration // The amount of time to wait between retries
Parallelism int // Set the parallelism setting for Terraform
OutputMaxLineSize int // The max size of one line in stdout and stderr (in bytes)
MaxRetries int // Maximum number of times to retry errors matching RetryableTerraformErrors
NoStderr bool // Disable stderr redirection
NoColor bool // Whether the -no-color flag will be set for any Terraform command or not
MigrateState bool // Set the -migrate-state and -force-copy (suppress 'yes' answer prompt) flag to the terraform init command
Reconfigure bool // Set the -reconfigure flag to the terraform init command
Upgrade bool // Whether the -upgrade flag of the terraform init command should be set to true or not
SetVarsAfterVarFiles bool // Pass -var options after -var-file options to Terraform commands
Lock bool // The lock option to pass to the terraform command with -lock
}
Options for running Terraform commands
func GetCommonOptions ¶ added in v0.10.4
GetCommonOptions extracts commons terraform options
func WithDefaultRetryableErrors ¶ added in v0.30.15
WithDefaultRetryableErrors makes a copy of the Options object and returns an updated object with sensible defaults for retryable errors. The included retryable errors are typical errors that most terraform modules encounter during testing, and are known to self resolve upon retrying. This will fail the test if there are any errors in the cloning process.
func (*Options) Clone ¶ added in v0.30.15
Clone makes a deep copy of most fields on the Options object and returns it.
NOTE: options.SshAgent and options.Logger CANNOT be deep copied (e.g., the SshAgent struct contains channels and listeners that can't be meaningfully copied), so the original values are retained.
type OutputKeyNotFound ¶ added in v0.15.12
type OutputKeyNotFound string
OutputKeyNotFound occurs when terraform output does not contain a value for the key specified in the function call
func (OutputKeyNotFound) Error ¶ added in v0.15.12
func (err OutputKeyNotFound) Error() string
type OutputValueNotList ¶ added in v0.15.12
type OutputValueNotList struct {
Value any
}
OutputValueNotList occurs when casting a found output value to a list of interfaces fails
func (OutputValueNotList) Error ¶ added in v0.15.12
func (err OutputValueNotList) Error() string
type OutputValueNotMap ¶ added in v0.15.12
type OutputValueNotMap struct {
Value any
}
OutputValueNotMap occurs when casting a found output value to a map fails
func (OutputValueNotMap) Error ¶ added in v0.15.12
func (err OutputValueNotMap) Error() string
type PanicWhileParsingVarFile ¶ added in v0.32.8
PanicWhileParsingVarFile is returned when the HCL parsing routine panics due to errors.
func (PanicWhileParsingVarFile) Error ¶ added in v0.32.8
func (err PanicWhileParsingVarFile) Error() string
type PlanStruct ¶ added in v0.32.19
type PlanStruct struct {
// A map that maps full resource addresses (e.g., module.foo.null_resource.test) to the planned values of that
// resource.
ResourcePlannedValuesMap map[string]*tfjson.StateResource
// A map that maps full resource addresses (e.g., module.foo.null_resource.test) to the planned actions terraform
// will take on that resource.
ResourceChangesMap map[string]*tfjson.ResourceChange
// The raw representation of the plan. See
// https://www.terraform.io/docs/internals/json-format.html#plan-representation for details on the structure of the
// plan output.
RawPlan tfjson.Plan
}
PlanStruct is a Go Struct representation of the plan object returned from Terraform (after running `terraform show`). Unlike the raw plan representation returned by terraform-json, this struct provides a map that maps the resource addresses to the changes and planned values to make it easier to navigate the raw plan struct.
func InitAndPlanAndShowWithStruct
deprecated
added in
v0.32.19
func InitAndPlanAndShowWithStruct(t testing.TestingT, options *Options) *PlanStruct
InitAndPlanAndShowWithStruct runs terraform init, then terraform plan, and then terraform show with the given options, and parses the json result into a go struct. This will fail the test if there is an error in the command.
Deprecated: Use InitAndPlanAndShowWithStructContext instead.
func InitAndPlanAndShowWithStructContext ¶ added in v1.0.0
func InitAndPlanAndShowWithStructContext(t testing.TestingT, ctx context.Context, options *Options) *PlanStruct
InitAndPlanAndShowWithStructContext runs terraform init, then terraform plan, and then terraform show with the given options, and parses the json result into a go struct. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func InitAndPlanAndShowWithStructContextE ¶ added in v1.0.0
func InitAndPlanAndShowWithStructContextE(t testing.TestingT, ctx context.Context, options *Options) (*PlanStruct, error)
InitAndPlanAndShowWithStructContextE runs terraform init, then terraform plan, and then terraform show with the given options, and parses the json result into a go struct. The context argument can be used for cancellation or timeout control.
func InitAndPlanAndShowWithStructE
deprecated
added in
v0.32.19
func InitAndPlanAndShowWithStructE(t testing.TestingT, options *Options) (*PlanStruct, error)
InitAndPlanAndShowWithStructE runs terraform init, then terraform plan, and then terraform show with the given options, and parses the json result into a go struct.
Deprecated: Use InitAndPlanAndShowWithStructContextE instead.
func InitAndPlanAndShowWithStructNoLogTempPlanFile
deprecated
added in
v0.37.1
func InitAndPlanAndShowWithStructNoLogTempPlanFile(t testing.TestingT, options *Options) *PlanStruct
InitAndPlanAndShowWithStructNoLogTempPlanFile runs InitAndPlanAndShowWithStruct without logging and also by allocating a temporary plan file destination that is discarded before returning the struct.
Deprecated: Use InitAndPlanAndShowWithStructNoLogTempPlanFileContext instead.
func InitAndPlanAndShowWithStructNoLogTempPlanFileContext ¶ added in v1.0.0
func InitAndPlanAndShowWithStructNoLogTempPlanFileContext(t testing.TestingT, ctx context.Context, options *Options) *PlanStruct
InitAndPlanAndShowWithStructNoLogTempPlanFileContext runs InitAndPlanAndShowWithStructContext without logging and also by allocating a temporary plan file destination that is discarded before returning the struct. The context argument can be used for cancellation or timeout control.
func ParsePlanJSON ¶ added in v0.43.8
func ParsePlanJSON(jsonStr string) (*PlanStruct, error)
ParsePlanJSON takes in the json string representation of the terraform plan and returns a go struct representation for easy introspection.
func ShowWithStruct
deprecated
added in
v0.40.16
func ShowWithStruct(t testing.TestingT, options *Options) *PlanStruct
ShowWithStruct calls terraform show in json mode with the given options, parses the json result into a PlanStruct, and returns it. This will fail the test if there is an error in the command.
Deprecated: Use ShowWithStructContext instead.
func ShowWithStructContext ¶ added in v1.0.0
ShowWithStructContext calls terraform show in json mode with the given options, parses the json result into a PlanStruct, and returns it. If PlanFilePath is set on the options, this will show the plan file. Otherwise, this will show the current state of the terraform module at options.TerraformDir. The context argument can be used for cancellation or timeout control. This will fail the test if there is an error in the command.
func ShowWithStructContextE ¶ added in v1.0.0
func ShowWithStructContextE(t testing.TestingT, ctx context.Context, options *Options) (*PlanStruct, error)
ShowWithStructContextE calls terraform show in json mode with the given options, parses the json result into a PlanStruct, and returns it. If PlanFilePath is set on the options, this will show the plan file. Otherwise, this will show the current state of the terraform module at options.TerraformDir. The context argument can be used for cancellation or timeout control.
func ShowWithStructE
deprecated
added in
v0.40.16
func ShowWithStructE(t testing.TestingT, options *Options) (*PlanStruct, error)
ShowWithStructE calls terraform show in json mode with the given options, parses the json result into a PlanStruct, and returns it.
Deprecated: Use ShowWithStructContextE instead.
type ResourceCount ¶ added in v0.17.1
ResourceCount represents counts of resources affected by terraform apply/plan/destroy command.
func GetResourceCount ¶ added in v0.17.1
func GetResourceCount(t testing.TestingT, 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 ¶ added in v0.17.1
func GetResourceCountE(t testing.TestingT, cmdout string) (*ResourceCount, error)
GetResourceCountE parses stdout/stderr of apply/plan/destroy commands and returns number of affected resources.
type UnexpectedOutputType ¶ added in v0.15.13
UnexpectedOutputType is an error that occurs when the output is not of the type we expect
func (UnexpectedOutputType) Error ¶ added in v0.15.13
func (err UnexpectedOutputType) Error() string
type UnsupportedDefaultWorkspaceDeletion ¶ added in v0.32.17
type UnsupportedDefaultWorkspaceDeletion struct{}
UnsupportedDefaultWorkspaceDeletion is returned when user tries to delete the workspace "default"
func (*UnsupportedDefaultWorkspaceDeletion) Error ¶ added in v0.32.17
func (err *UnsupportedDefaultWorkspaceDeletion) Error() string
type Var ¶ added in v0.49.0
type Var interface {
// Args returns the command-line arguments that pass this variable to Terraform.
Args() []string
// contains filtered or unexported methods
}
Var represents a Terraform variable assignment that can be rendered as command-line arguments. Use VarInline to pass an inline value with -var, or VarFile to reference a -var-file on disk.
type VarFileNotFound ¶ added in v0.32.6
type VarFileNotFound struct {
Path string
}
VarFileNotFound is an error that occurs when a var file cannot be found in an option's VarFile list
func (VarFileNotFound) Error ¶ added in v0.32.6
func (err VarFileNotFound) Error() string
type WorkspaceDoesNotExist ¶ added in v0.32.17
type WorkspaceDoesNotExist string
WorkspaceDoesNotExist is returned when user tries to delete a workspace which does not exist
func (WorkspaceDoesNotExist) Error ¶ added in v0.32.17
func (err WorkspaceDoesNotExist) Error() string