Environment Variables
The env section in atmos.yaml defines global environment variables that are automatically set for all Atmos operations. Use this to configure tools, inject credentials, or set defaults that apply across your entire project.
You will learn
- Set environment variables once, use everywhere
- Works seamlessly with Atmos profiles for environment-specific configuration
- Supports YAML functions like
!envand!execfor dynamic values - Import dotenv files explicitly with
!include - Variables are merged with system environment (global env can override system, component env overrides global)
Configuration
Configure global environment variables in the env section of your atmos.yaml:
Including Dotenv Files
Use !include to load values from a dotenv file directly into the CLI env section:
Use YAML merge keys when you want to include dotenv values and also define inline overrides. The << key is YAML's merge-key syntax, the same YAML mechanism commonly used with anchors and aliases:
Atmos parses .env, .env.*, and *.env files as dotenv key/value files when they are included with !include. The included values become a map, so standard YAML merge behavior applies: keys written directly under env override keys loaded from the dotenv file.
Use !include.raw when you need the raw file contents instead of parsed dotenv values.
You can layer multiple dotenv files with a YAML merge sequence:
YAML merge sequence precedence is earlier item wins. In the example above, .env.local has higher precedence than .env, so .env.local overrides .env. Keys written directly under env, such as AWS_REGION, override all merged dotenv values.
Local dotenv paths follow the existing !include resolution rules. Use ./ or ../ for paths relative to the YAML file containing the include; bare local paths such as .env follow Atmos' normal current/base-path lookup for includes. Absolute paths are honored.
Atmos does not automatically load dotenv files, and it does not load or execute .envrc files. Dotenv support is explicit through !include.
Pinning Atmos Configuration Per Project
Keys in the global env section that begin with the ATMOS_ prefix configure Atmos itself, not just the tools Atmos runs. When Atmos loads atmos.yaml, it promotes any ATMOS_* variables from the env section into its own process environment before it resolves things like the active profile. This lets you pin a profile per project by committing a dotenv file:
With this in place, running any atmos command in the project uses the dev profile automatically — no --profile flag or exported ATMOS_PROFILE required. The same applies to other Atmos settings such as ATMOS_BASE_PATH.
An exported environment variable always wins: if ATMOS_PROFILE is already set in your shell, the value in the env section is not applied. This keeps ad-hoc overrides (ATMOS_PROFILE=ci atmos …) working as expected.
To pin ATMOS_PROFILE, the env: !include .env must live in your base atmos.yaml (not inside a profile), since it has to be resolved before the profile is selected. Only ATMOS_-prefixed keys are promoted into Atmos' own environment; all other env keys continue to flow only to the tools Atmos runs (Terraform, Helmfile, etc.).
envA map of environment variable names to values. Values can be literal strings or use YAML functions for dynamic values.
Type:
map[string]stringDefault: Not set
Precedence
Environment variables are merged in the following order (lowest to highest priority):
| Priority | Source | Description |
|---|---|---|
| 1 (lowest) | System environment | Variables from your shell (os.Environ()) |
| 2 | Global env in atmos.yaml | Variables defined in CLI configuration |
| 3 (highest) | Component/stack env | Variables defined in stack manifests |
This means:
- Global
envinatmos.yamlcan override system environment variables - Component-level
envin stacks can override globalenv
Special Handling for Terraform CLI Args
Variables starting with TF_CLI_ARGS_ receive special handling. Instead of replacing, new values are prepended to existing values, allowing you to layer Terraform arguments:
# atmos.yaml
env:
TF_CLI_ARGS_plan: "-compact-warnings"
# If TF_CLI_ARGS_plan is already set to "-lock=false" in your shell,
# the final value becomes: "-compact-warnings -lock=false"
YAML Functions
The env section supports YAML functions for dynamic values:
Reading from Other Environment Variables
Use !env to read values from the current environment:
env:
# Copy GH_TOKEN to GITHUB_TOKEN if it exists
GITHUB_TOKEN: !env GH_TOKEN
# With a default value if not set
AWS_PROFILE: !env MY_AWS_PROFILE default
Executing Commands
Use !exec to set values from command output:
env:
# Get GitHub token from gh CLI
GITHUB_TOKEN: !exec gh auth token
# Get AWS account ID
AWS_ACCOUNT_ID: !exec aws sts get-caller-identity --query Account --output text
Use Cases
GitHub Token for Private Terraform Modules
When using private GitHub repositories as Terraform module sources, set GITHUB_TOKEN:
This enables Terraform to authenticate when downloading modules:
module "vpc" {
source = "git::https://github.com/myorg/terraform-aws-vpc.git?ref=v1.0.0"
}
Terraform Plugin Cache
Speed up Terraform operations by caching providers:
AWS SDK Configuration
Configure AWS SDK behavior globally:
OpenTofu Configuration
Set OpenTofu-specific environment variables:
Using with Atmos Profiles
The env section becomes powerful when combined with Atmos profiles. Define environment-specific variables in profile configurations:
Local Development Profile
CI/CD Profile
Usage
# Local development - uses gh CLI for GitHub token
atmos --profile developer terraform plan vpc -s prod
# CI/CD - uses existing GITHUB_TOKEN from CI environment
ATMOS_PROFILE=ci atmos terraform apply vpc -s prod --auto-approve
This pattern allows you to:
- Use
gh auth tokenlocally (no token management) - Use CI-provided
GITHUB_TOKENin pipelines (secure, no secrets in config) - Keep your base
atmos.yamlclean of environment-specific settings