config

package
v1.202.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 41 Imported by: 0

README

Import Config

flowchart TD
    A["Load Configuration File"] --> B{"Import Section Exists?"}

    B -- Yes --> C["Process Imports in Order"]
    C --> D{"Import Type?"}
    D --> E["Remote URL"]
    D --> F["Specific Path"]
    D --> G["Wildcard Globs"]

    E --> H["Fetch Config from Remote URL"]
    F --> I["Read Config from Filesystem"]
    G --> I["Read Config from Filesystem"]

    H --> J["Call Load Configuration File (Recursively)"]
    I --> J["Call Load Configuration File (Recursively)"]

    J --> L["Deep Merge with Current Config in Memory"]
    L --> K{"More Imports to Process?"}
    K -- Yes --> C
    K -- No --> M["Configuration Processing Complete"]

    %% Loopback for recursion
    J -.-> A

    %% Styling for clarity
    style A fill:#A8DADC,stroke:#1D3557,stroke-width:2px,color:#000000
    style B fill:#F4A261,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style C fill:#457B9D,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style D fill:#A8DADC,stroke:#1D3557,stroke-width:2px,color:#000000
    style E fill:#E63946,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style F fill:#E63946,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style G fill:#E63946,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style H fill:#A8DADC,stroke:#1D3557,stroke-width:2px,color:#000000
    style I fill:#A8DADC,stroke:#1D3557,stroke-width:2px,color:#000000
    style J fill:#F4A261,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style L fill:#457B9D,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style K fill:#F4A261,stroke:#1D3557,stroke-width:2px,color:#FFFFFF
    style M fill:#1D3557,stroke:#1D3557,stroke-width:2px,color:#FFFFFF

    classDef recursion stroke-dasharray: 5 5;

Documentation

Overview

Package config is a generated GoMock package.

Index

Constants

View Source
const (
	AtmosCommand         = "atmos"
	CliConfigFileName    = "atmos"
	DotCliConfigFileName = ".atmos"

	SystemDirConfigFilePath = "/usr/local/etc/atmos"
	WindowsAppDataEnvVar    = "LOCALAPPDATA"

	// Config file names for local configuration detection.
	AtmosConfigFileName    = "atmos.yaml"
	DotAtmosConfigFileName = ".atmos.yaml"

	// Config directory names for local configuration detection.
	AtmosConfigDirName            = ".atmos"
	AtmosDefaultImportsDirName    = "atmos.d"
	DotAtmosDefaultImportsDirName = ".atmos.d"

	// GlobalOptionsFlag is a custom flag to specify helmfile `GLOBAL OPTIONS`
	// https://github.com/roboll/helmfile#cli-reference
	GlobalOptionsFlag = "--global-options"

	TerraformCommandFlag        = "--terraform-command"
	TerraformDirFlag            = "--terraform-dir"
	HelmfileCommandFlag         = "--helmfile-command"
	HelmfileDirFlag             = "--helmfile-dir"
	PackerCommandFlag           = "--packer-command"
	PackerDirFlag               = "--packer-dir"
	CliConfigDirFlag            = "--config-dir"
	StackDirFlag                = "--stacks-dir"
	BasePathFlag                = "--base-path"
	VendorBasePathFlag          = "--vendor-base-path"
	WorkflowDirFlag             = "--workflows-dir"
	KubeConfigConfigFlag        = "--kubeconfig-path"
	JsonSchemaDirFlag           = "--schemas-jsonschema-dir"
	OpaDirFlag                  = "--schemas-opa-dir"
	CueDirFlag                  = "--schemas-cue-dir"
	AtmosManifestJsonSchemaFlag = "--schemas-atmos-manifest"

	DeployRunInitFlag           = "--deploy-run-init"
	AutoGenerateBackendFileFlag = "--auto-generate-backend-file"
	AppendUserAgentFlag         = "--append-user-agent"
	InitRunReconfigure          = "--init-run-reconfigure"
	InitPassVars                = "--init-pass-vars"
	PlanSkipPlanfile            = "--skip-planfile"

	FromPlanFlag       = "--from-plan"
	PlanFileFlag       = "--planfile"
	DryRunFlag         = "--dry-run"
	SkipInitFlag       = "--skip-init"
	RedirectStdErrFlag = "--redirect-stderr"

	HelpFlag1 = "-h"
	HelpFlag2 = "--help"

	TerraformComponentType = "terraform"
	HelmfileComponentType  = "helmfile"
	PackerComponentType    = "packer"

	ComponentVendorConfigFileName = "component.yaml"
	AtmosVendorConfigFileName     = "vendor"

	ImportSectionName                 = "import"
	NameSectionName                   = "name"
	OverridesSectionName              = "overrides"
	ProvidersSectionName              = "providers"
	HooksSectionName                  = "hooks"
	VarsSectionName                   = "vars"
	SettingsSectionName               = "settings"
	LocalsSectionName                 = "locals"
	EnvSectionName                    = "env"
	BackendSectionName                = "backend"
	BackendTypeSectionName            = "backend_type"
	RemoteStateBackendSectionName     = "remote_state_backend"
	RemoteStateBackendTypeSectionName = "remote_state_backend_type"
	MetadataSectionName               = "metadata"
	ComponentSectionName              = "component"
	ComponentsSectionName             = "components"
	CommandSectionName                = "command"
	TerraformSectionName              = "terraform"
	HelmfileSectionName               = "helmfile"
	PackerSectionName                 = "packer"
	PackerTemplateSectionName         = "template"
	WorkspaceSectionName              = "workspace"
	AuthSectionName                   = "auth"
	InheritanceSectionName            = "inheritance"
	IntegrationsSectionName           = "integrations"
	GithubSectionName                 = "github"
	ProcessEnvSectionName             = "process_env"
	CliArgsSectionName                = "cli_args"
	TerraformCliVarsSectionName       = "tf_cli_vars"
	TerraformCliArgsEnvSectionName    = "env_tf_cli_args"
	TerraformCliVarsEnvSectionName    = "env_tf_cli_vars"
	ComponentTypeSectionName          = "component_type"
	OutputsSectionName                = "outputs"
	StaticSectionName                 = "static"
	BackendTypeLocal                  = "local"
	BackendTypeS3                     = "s3"
	BackendTypeAzurerm                = "azurerm"
	BackendTypeGCS                    = "gcs"
	BackendTypeCloud                  = "cloud"
	ComponentPathSectionName          = "component_path"
	InheritsSectionName               = "inherits"
	AbstractSectionName               = "abstract"

	LogsLevelFlag = "--logs-level"
	LogsFileFlag  = "--logs-file"

	QueryFlag    = "--query"
	AffectedFlag = "--affected"
	AllFlag      = "--all"

	ProcessTemplatesFlag = "--process-templates"
	ProcessFunctionsFlag = "--process-functions"
	SkipFlag             = "--skip"

	SettingsListMergeStrategyFlag = "--settings-list-merge-strategy"

	// Atmos Pro.
	AtmosProBaseUrlEnvVarName     = "ATMOS_PRO_BASE_URL"
	AtmosProEndpointEnvVarName    = "ATMOS_PRO_ENDPOINT"
	AtmosProTokenEnvVarName       = "ATMOS_PRO_TOKEN"
	AtmosProWorkspaceIDEnvVarName = "ATMOS_PRO_WORKSPACE_ID"
	AtmosProRunIDEnvVarName       = "ATMOS_PRO_RUN_ID"
	AtmosProDefaultBaseUrl        = "https://atmos-pro.com"
	AtmosProDefaultEndpoint       = "api/v1"
	UploadStatusFlag              = "upload-status"

	TerraformDefaultWorkspace = "default"

	ComponentStr = "component"
	StackStr     = "stack"

	// Auth flags.
	IdentityFlagName          = "identity" // Flag name without prefix.
	IdentityFlag              = "--identity"
	IdentityFlagSelectValue   = "__SELECT__"   // Special value when --identity is used without argument.
	IdentityFlagDisabledValue = "__DISABLED__" // Special value when --identity=false (skip authentication).

	// Performance profiling flags.
	ProfilerEnabledFlag = "--profiler-enabled"
	ProfilerHostFlag    = "--profiler-host"
	ProfilerPortFlag    = "--profiler-port"
	ProfilerFileFlag    = "--profiler-file"
	ProfilerTypeFlag    = "--profiler-type"
	HeatmapFlag         = "--heatmap"
	HeatmapModeFlag     = "--heatmap-mode"

	// AtmosProfileFlag is the CLI flag for specifying Atmos profiles.
	AtmosProfileFlag = "--profile"
)
View Source
const (
	LOCAL  importTypes = 0
	REMOTE importTypes = 1
)
View Source
const (

	// AtmosCliConfigPathEnvVar is the environment variable name for CLI config path.
	AtmosCliConfigPathEnvVar = "ATMOS_CLI_CONFIG_PATH"
)
View Source
const (
	// CacheDirPermissions is the default permission for cache directory (read/write/execute for owner, read/execute for group and others).
	CacheDirPermissions = 0o755
)
View Source
const (
	// MaximumImportLvL defines the maximum import level allowed.
	MaximumImportLvL = 10
)

Variables

View Source
var ErrExecuteYamlFunctions = errors.New("failed to execute yaml function")
View Source
var (
	NotFound = errors.New("\n'atmos.yaml' CLI config was not found in any of the searched paths: system dir, home dir, current dir, ENV vars." +
		"\nYou can download a sample config and adapt it to your requirements from " +
		"https://raw.githubusercontent.com/cloudposse/atmos/main/examples/quick-start-advanced/atmos.yaml")
)

Functions

func AtmosConfigAbsolutePaths added in v1.193.0

func AtmosConfigAbsolutePaths(atmosConfig *schema.AtmosConfiguration) error

func FindAllStackConfigsInPaths added in v1.4.13

func FindAllStackConfigsInPaths(
	atmosConfig *schema.AtmosConfiguration,
	includeStackPaths []string,
	excludeStackPaths []string,
) ([]string, []string, error)

FindAllStackConfigsInPaths finds all stack manifests in the paths specified by globs.

func FindAllStackConfigsInPathsForStack added in v1.4.13

func FindAllStackConfigsInPathsForStack(
	atmosConfig schema.AtmosConfiguration,
	stack string,
	includeStackPaths []string,
	excludeStackPaths []string,
) ([]string, []string, bool, error)

FindAllStackConfigsInPathsForStack finds all stack manifests in the paths specified by globs for the provided stack.

func GetCacheFilePath added in v1.127.0

func GetCacheFilePath() (string, error)

GetCacheFilePath returns the filesystem path to the Atmos cache file. It respects ATMOS_XDG_CACHE_HOME and XDG_CACHE_HOME environment variables for cache directory location. Returns an error if xdg.GetXDGCacheDir fails or if the cache directory cannot be created.

func GetContextFromVars added in v1.3.5

func GetContextFromVars(vars map[string]any) schema.Context

GetContextFromVars creates a context object from the provided variables.

func GetContextPrefix added in v1.3.5

func GetContextPrefix(stack string, context schema.Context, stackNamePattern string, stackFile string) (string, error)

GetContextPrefix calculates context prefix from the context.

func GetStackNameFromContextAndStackNamePattern added in v1.4.9

func GetStackNameFromContextAndStackNamePattern(
	namespace string,
	tenant string,
	environment string,
	stage string,
	stackNamePattern string,
) (string, error)

GetStackNameFromContextAndStackNamePattern calculates stack name from the provided context using the provided stack name pattern.

func InitCliConfig added in v1.10.0

func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks bool) (schema.AtmosConfiguration, error)

InitCliConfig finds and merges CLI configurations in the following order: system dir, home dir, current dir, ENV vars, command-line arguments https://dev.to/techschoolguru/load-config-from-file-environment-variables-in-golang-with-viper-2j2d https://medium.com/@bnprashanth256/reading-configuration-files-and-environment-variables-in-go-golang-c2607f912b63

NOTE: Global flags (like --profile) must be synced to Viper before calling this function. This is done by syncGlobalFlagsToViper() in cmd/root.go PersistentPreRun.

TODO: Change configAndStacksInfo to pointer. Temporarily suppressing gocritic warnings; refactoring InitCliConfig would require extensive changes.

func LoadConfig added in v1.167.0

func LoadConfig(configAndStacksInfo *schema.ConfigAndStacksInfo) (schema.AtmosConfiguration, error)

LoadConfig loads the Atmos configuration from multiple sources in order of precedence: * Embedded atmos.yaml (`atmos/pkg/config/atmos.yaml`) * System dir (`/usr/local/etc/atmos` on Linux, `%LOCALAPPDATA%/atmos` on Windows). * Home directory (~/.atmos). * Current working directory. * ENV vars. * Command-line arguments.

NOTE: Global flags (like --profile) must be synced to Viper before calling this function. This is done by syncGlobalFlagsToViper() in cmd/root.go PersistentPreRun.

func LoadStackAuthDefaults added in v1.201.0

func LoadStackAuthDefaults(atmosConfig *schema.AtmosConfiguration) (map[string]bool, error)

LoadStackAuthDefaults loads stack configuration files for auth identity defaults. This is a lightweight load that doesn't process templates or YAML functions. It returns a map of identity names to their default status found in stack configs.

The loader looks for:

auth:
  identities:
    <identity-name>:
      default: true

This function is used to resolve stack-level default identities before full stack processing, solving the chicken-and-egg problem where we need to know the default identity to authenticate, but stack configs are only loaded after authentication is configured.

func MergeStackAuthDefaults added in v1.201.0

func MergeStackAuthDefaults(authConfig *schema.AuthConfig, stackDefaults map[string]bool)

MergeStackAuthDefaults merges stack-level auth defaults into the auth config. Stack defaults have HIGHER priority than atmos.yaml defaults (following Atmos inheritance model). This means stack config can override the default identity set in atmos.yaml.

func ReplaceContextTokens added in v1.3.5

func ReplaceContextTokens(context schema.Context, pattern string) string

ReplaceContextTokens replaces context tokens in the provided pattern and returns a string with all the tokens replaced.

func SaveCache added in v1.127.0

func SaveCache(cfg CacheConfig) error

SaveCache writes the provided cache configuration to the cache file atomically. The function acquires an exclusive lock to prevent concurrent writes and ensures data consistency across multiple processes.

Parameters:

  • cfg: The CacheConfig to save to disk.

Returns an error if the cache file cannot be created or written. Callers can check for specific failure types using errors.Is() with the following sentinel errors:

  • ErrCacheMarshal: Failed to marshal cache content to YAML
  • ErrCacheWrite: Failed to write the cache file

func SearchAtmosConfig added in v1.167.0

func SearchAtmosConfig(path string) ([]string, error)

SearchAtmosConfig searches for a config file in path. The path is directory, file or a pattern.

func SearchConfigFile added in v1.117.0

func SearchConfigFile(configPath string, atmosConfig schema.AtmosConfiguration) (string, error)

func ShouldCheckForUpdates added in v1.127.0

func ShouldCheckForUpdates(lastChecked int64, frequency string) bool

ShouldCheckForUpdates determines whether an update check is due based on the configured frequency and the time of the last check.

func UpdateCache added in v1.192.0

func UpdateCache(update func(*CacheConfig)) error

UpdateCache atomically updates the cache file by acquiring a lock, loading the current configuration, applying the update function, and saving the result. This prevents race conditions when multiple processes try to update different fields simultaneously.

Parameters:

  • update: A function that modifies the provided CacheConfig in place.

Returns an error if the cache file cannot be accessed, read, or written. Callers can check for specific failure types using errors.Is() with the following sentinel errors:

  • ErrCacheRead: Failed to read the cache file
  • ErrCacheUnmarshal: Failed to unmarshal cache content
  • ErrCacheWrite: Failed to write the cache file
  • ErrCacheMarshal: Failed to marshal cache content

Types

type CacheConfig added in v1.127.0

type CacheConfig struct {
	LastChecked                int64  `mapstructure:"last_checked" yaml:"last_checked"`
	InstallationId             string `mapstructure:"installation_id" yaml:"installation_id"`
	TelemetryDisclosureShown   bool   `mapstructure:"telemetry_disclosure_shown" yaml:"telemetry_disclosure_shown"`
	BrowserSessionWarningShown bool   `mapstructure:"browser_session_warning_shown" yaml:"browser_session_warning_shown"`
}

func LoadCache added in v1.127.0

func LoadCache() (CacheConfig, error)

type DefaultLoader added in v1.195.0

type DefaultLoader struct{}

DefaultLoader implements Loader using real config operations.

func (*DefaultLoader) InitCliConfig added in v1.195.0

func (d *DefaultLoader) InitCliConfig(configAndStacksInfo *schema.ConfigAndStacksInfo, processStacks bool) (schema.AtmosConfiguration, error)

InitCliConfig initializes the CLI configuration.

type Loader added in v1.195.0

type Loader interface {
	// InitCliConfig initializes the CLI configuration.
	InitCliConfig(configAndStacksInfo *schema.ConfigAndStacksInfo, processStacks bool) (schema.AtmosConfiguration, error)
}

Loader defines operations for loading Atmos configuration. This interface allows mocking of config loading in tests.

type MockLoader added in v1.195.0

type MockLoader struct {
	// contains filtered or unexported fields
}

MockLoader is a mock of Loader interface.

func NewMockLoader added in v1.195.0

func NewMockLoader(ctrl *gomock.Controller) *MockLoader

NewMockLoader creates a new mock instance.

func (*MockLoader) EXPECT added in v1.195.0

func (m *MockLoader) EXPECT() *MockLoaderMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLoader) InitCliConfig added in v1.195.0

func (m *MockLoader) InitCliConfig(configAndStacksInfo *schema.ConfigAndStacksInfo, processStacks bool) (schema.AtmosConfiguration, error)

InitCliConfig mocks base method.

type MockLoaderMockRecorder added in v1.195.0

type MockLoaderMockRecorder struct {
	// contains filtered or unexported fields
}

MockLoaderMockRecorder is the mock recorder for MockLoader.

func (*MockLoaderMockRecorder) InitCliConfig added in v1.195.0

func (mr *MockLoaderMockRecorder) InitCliConfig(configAndStacksInfo, processStacks any) *gomock.Call

InitCliConfig indicates an expected call of InitCliConfig.

type ProfileLocation added in v1.199.0

type ProfileLocation struct {
	Path       string // Absolute path to profile directory.
	Type       string // "configurable", "project-hidden", "xdg", "project".
	Precedence int    // Lower number = higher precedence.
}

ProfileLocation represents a location where profiles can be stored.

type ResolvedPaths added in v1.167.0

type ResolvedPaths struct {
	// contains filtered or unexported fields
}

import Resolved Paths.

Directories

Path Synopsis
Package casemap provides utilities for preserving original case of YAML map keys.
Package casemap provides utilities for preserving original case of YAML map keys.

Jump to

Keyboard shortcuts

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