atmos

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 13 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 FormatTerraformPlanFileAsArg

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

func GetExitCodeForAtmosCommand

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

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

func GetExitCodeForAtmosCommandE

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

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

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 testing.TestingT, additionalOptions *Options, args ...string) string

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

func RunAtmosCommandAndGetStdoutE

func RunAtmosCommandAndGetStdoutE(t testing.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 testing.TestingT, additionalOptions *Options, additionalArgs ...string) (string, error)

RunAtmosCommandE runs atmos with the given arguments and 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 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
}

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.

Jump to

Keyboard shortcuts

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