atmos

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AtmosDefaultPath command to run atmos
	AtmosDefaultPath = "atmos"
)
View Source
const DefaultErrorExitCode = 1

DefaultErrorExitCode is the exit code returned when atmos command fails

View Source
const DefaultSuccessExitCode = 0

DefaultSuccessExitCode is the exit code returned when atmos command succeeds

View Source
const TerraformPlanChangesPresentExitCode = 2

TerraformPlanChangesPresentExitCode is the exit code returned by atmos terraform plan detailed exitcode when changes are present

Variables

View Source
var (
	ErrorComponentRequired    = fmt.Errorf("you must set Component on options struct to use this function")
	ErrorPlanFilePathRequired = fmt.Errorf("you must set PlanFilePath on options struct to use this function")
	ErrorStackRequired        = fmt.Errorf("you must set Stack on options struct to use this function")
)

Custom errors

View Source
var DefaultExecutable = defaultAtmosExecutable()
View Source
var (
	DefaultRetryableAtmosErrors = 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.",
	}
)
View Source
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

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

Apply runs atmos 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 ApplyAndIdempotent

func ApplyAndIdempotent(t testing.TestingT, options *Options) string

ApplyAndIdempotent runs atmos 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.

func ApplyAndIdempotentE

func ApplyAndIdempotentE(t testing.TestingT, options *Options) (string, error)

ApplyAndIdempotentE runs atmos 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.

func ApplyE

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

ApplyE runs atmos 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.TestingT, options *Options) string

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

func DestroyE

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

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

func FormatArgs

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

func FormatAtmosTerraformArgs

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

FormatTerraformArgs 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 FormatAtmosVendorArgs

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

FormatAtmosVendorArgs converts the inputs to a format palatable to atmos vendor.

func FormatTerraformPlanFileAsArg

func FormatTerraformPlanFileAsArg(commandType string, outPath string) []string

func GetExitCodeForAtmosCommand

func GetExitCodeForAtmosCommand(t tt.TestingT, additionalOptions *Options, args ...string) int

GetExitCodeForAtmosCommand runs atmos with the given arguments and options and returns exit code

func GetExitCodeForAtmosCommandE

func GetExitCodeForAtmosCommandE(t tt.TestingT, additionalOptions *Options, additionalArgs ...string) (int, error)

GetExitCodeForAtmosCommandE runs atmos with the given arguments and options and returns exit code

func Output

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

Output calls atmos 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.

func OutputAll

func OutputAll(t testing.TestingT, options *Options) map[string]interface{}

OutputAll calls terraform output returns all values as a map. If there is error fetching the output, fails the test

func OutputAllE

func OutputAllE(t testing.TestingT, options *Options) (map[string]interface{}, error)

OutputAllE calls terraform and returns all the outputs as a map

func OutputE

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

OutputE calls atmos 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.

func OutputForKeys

func OutputForKeys(t testing.TestingT, options *Options, keys []string) map[string]interface{}

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

func OutputForKeysE(t testing.TestingT, options *Options, keys []string) (map[string]interface{}, error)

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 OutputJson

func OutputJson(t testing.TestingT, options *Options, key string) string

OutputJson calls terraform output for the given variable and returns the result as the json string. If key is an empty string, it will return all the output variables.

func OutputJsonE

func OutputJsonE(t testing.TestingT, options *Options, key string) (string, error)

OutputJsonE calls terraform output for the given variable and returns the result as the json string. If key is an empty string, it will return all the output variables.

func OutputList

func OutputList(t testing.TestingT, 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

func OutputListE(t testing.TestingT, 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 OutputListOfObjects

func OutputListOfObjects(t testing.TestingT, options *Options, key string) []map[string]interface{}

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.

func OutputListOfObjectsE

func OutputListOfObjectsE(t testing.TestingT, options *Options, key string) ([]map[string]interface{}, 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.

func OutputMap

func OutputMap(t testing.TestingT, 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

func OutputMapE(t testing.TestingT, 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 OutputMapOfObjects

func OutputMapOfObjects(t testing.TestingT, options *Options, key string) map[string]interface{}

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.

func OutputMapOfObjectsE

func OutputMapOfObjectsE(t testing.TestingT, options *Options, key string) (map[string]interface{}, error)

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.

func OutputRequired

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

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

func OutputRequiredE

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

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

func OutputStruct

func OutputStruct(t testing.TestingT, options *Options, key string, v interface{})

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.

func OutputStructE

func OutputStructE(t testing.TestingT, options *Options, key string, v interface{}) error

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.

func Plan

func Plan(t testing.TestingT, options *Options) string

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 PlanE

func PlanE(t testing.TestingT, options *Options) (string, error)

PlanE runs terraform plan with the given options and returns stdout/stderr.

func PlanExitCode

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

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

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

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

func RunAtmosCommand

func RunAtmosCommand(t tt.TestingT, additionalOptions *Options, args ...string) string

RunAtmosCommand runs atmos with the given arguments and options and return stdout/stderr.

func RunAtmosCommandAndGetStdoutE

func RunAtmosCommandAndGetStdoutE(t tt.TestingT, additionalOptions *Options, additionalArgs ...string) (string, error)

RunAtmosCommandAndGetStdoutE runs atmos with the given arguments and options and returns solely its stdout (but not stderr).

func RunAtmosCommandE

func RunAtmosCommandE(t tt.TestingT, additionalOptions *Options, additionalArgs ...string) (string, error)

RunAtmosCommandE runs atmos with the given arguments and options and return stdout/stderr.

func VendorPull

func VendorPull(t testing.TestingT, options *Options) string

Vendor runs atmos vendor with the given options and return stdout/stderr.

func VendorPullE

func VendorPullE(t testing.TestingT, options *Options) (string, error)

VendorPullE runs atmos vendor with the given options and return stdout/stderr.

Types

type DescribeStacksComponent

type DescribeStacksComponent struct {
	Component map[string]any `json:"component"`
}

type DescribeStacksOutput

type DescribeStacksOutput struct {
	Stacks map[string]DescribeStacksComponent
}

type DescribeStacksTerraform

type DescribeStacksTerraform struct {
	Terraform map[string]DescribeStacksTerraformComponent `json:"terraform"`
}

type DescribeStacksTerraformComponent

type DescribeStacksTerraformComponent struct {
	AtmosComponent         string      `json:"atmos_component"`
	AtmosStack             string      `json:"atmos_stack"`
	AtmosStackFile         string      `json:"atmos_stack_file"`
	Backend                interface{} `json:"backend"`
	BackendType            string      `json:"backend_type"`
	Command                string      `json:"command"`
	Component              string      `json:"component"`
	Env                    interface{} `json:"env"`
	Inheritance            interface{} `json:"inheritance"`
	Metadata               interface{} `json:"metadata"`
	Overrides              interface{} `json:"overrides"`
	RemoteStateBackend     interface{} `json:"remote_state_backend"`
	RemoteStateBackendType string      `json:"remote_state_backend_type"`
	Settings               interface{} `json:"settings"`
	Vars                   interface{} `json:"vars"`
	Workspace              string      `json:"workspace"`
}

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 InputFileKeyNotFound

type InputFileKeyNotFound struct {
	FilePath string
	Key      string
}

InputFileKeyNotFound occurs when tfvar file does not contain a value for the key specified in the function call

func (InputFileKeyNotFound) Error

func (err InputFileKeyNotFound) Error() string

type Options

type Options struct {
	AtmosBinary   string // Name of the binary that will be used
	AtmosBasePath string // The path of the atmos root for components and stacks

	// The vars to pass to Atmos commands using the -var option. Note that atmos does not support passing `null`
	// as a variable value through the command line. That is, if you use `map[string]interface{}{"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]interface{}{
	//     "foo": map[string]interface{}{"bar": nil},
	// }
	Vars                      map[string]interface{}
	VarFiles                  []string               // The var file paths to pass to Atmos commands using -var-file option.
	Stack                     string                 // The stack to pass to the atmos command with -stack
	Component                 string                 // The component to pass to the atmos terraform command
	Targets                   []string               // The target resources to pass to the atmos command with -target
	Lock                      bool                   // The lock option to pass to the atmos command with -lock
	LockTimeout               string                 // The lock timeout option to pass to the atmos command with -lock-timeout
	EnvVars                   map[string]string      // Environment variables to set when running Atmos
	BackendConfig             map[string]interface{} // The vars to pass to the atmos init command for extra configuration for the backend
	RetryableAtmosErrors      map[string]string      // If Atmos 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 RetryableAtmosErrors
	TimeBetweenRetries        time.Duration          // The amount of time to wait between retries
	Upgrade                   bool                   // Whether the -upgrade flag of the atmos init command should be set to true or not
	Reconfigure               bool                   // Set the -reconfigure flag to the atmos init command
	MigrateState              bool                   // Set the -migrate-state and -force-copy (suppress 'yes' answer prompt) flag to the atmos init command
	NoColor                   bool                   // Whether the -no-color flag will be set for any Atmos command or not
	RedirectStrErrDestination string                 // The destination to redirect stderr to. If nil, stderr will not be redirected.
	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)
	Logger                    *logger.Logger         // Set a non-default logger that should be used. See the logger package for more info.
	Parallelism               int                    // Set the parallelism setting for Atmos
	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 atmos init command (-plugin-dir)
	SetVarsAfterVarFiles      bool                   // Pass -var options after -var-file options to Atmos 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.
	VendorComponent           string                 // The component to pass to the atmos vendor command, if not passed all components will be vendored
	VendorStack               string                 // The stack to pass to the atmos vendor command, if not passed all stacks will be vendored
	VendorTags                []string               // The tags to pass to the atmos vendor command, if not passed all tags will be vendored
	VendorType                string                 // The type of vendor to pass to the atmos vendor command, if not passed `terraform` will be used
}

Options for running Atmos commands

func GetCommonOptions

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

GetCommonOptions extracts commons atmos options

func WithDefaultRetryableErrors

func WithDefaultRetryableErrors(t testing.TestingT, originalOptions *Options) *Options

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 atmos 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

func (options *Options) Clone() (*Options, error)

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

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 PanicWhileParsingVarFile

type PanicWhileParsingVarFile struct {
	ConfigFile     string
	RecoveredValue interface{}
}

PanicWhileParsingVarFile is returned when the HCL parsing routine panics due to errors.

func (PanicWhileParsingVarFile) Error

func (err PanicWhileParsingVarFile) Error() string

type UnexpectedOutputType

type UnexpectedOutputType struct {
	Key          string
	ExpectedType string
	ActualType   string
}

UnexpectedOutputType is an error that occurs when the output is not of the type we expect

func (UnexpectedOutputType) Error

func (err UnexpectedOutputType) Error() string

type UnsupportedDefaultWorkspaceDeletion

type UnsupportedDefaultWorkspaceDeletion struct{}

UnsupportedDefaultWorkspaceDeletion is returned when user tries to delete the workspace "default"

func (*UnsupportedDefaultWorkspaceDeletion) Error

type VarFileNotFound

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

func (err VarFileNotFound) Error() string

type WorkspaceDoesNotExist

type WorkspaceDoesNotExist string

WorkspaceDoesNotExist is returned when user tries to delete a workspace which does not exist

func (WorkspaceDoesNotExist) Error

func (err WorkspaceDoesNotExist) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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