atmos env
Output environment variables from the env section of atmos.yaml in various formats suitable for shell evaluation, .env files, JSON consumption, or GitHub Actions workflows.
Usage
atmos env [--format bash|json|dotenv|github] [--output <file>]
How It Works
The atmos env command reads the env section from your atmos.yaml configuration (including any active profiles) and outputs the environment variables in your chosen format. This is useful for:
- Exporting Atmos-configured environment variables to your shell
- Generating
.envfiles for other tools - Integrating with CI/CD pipelines, especially GitHub Actions
- Inspecting what environment variables Atmos will set
Examples
Shell Evaluation
Load environment variables into your current shell:
# Load env vars into current shell
eval $(atmos env)
# Now tools like Terraform can use GITHUB_TOKEN, TF_PLUGIN_CACHE_DIR, etc.
terraform init
Using with Profiles
Profiles are automatically applied when specified:
# Use CI profile
eval $(atmos env --profile ci)
# Or via environment variable
ATMOS_PROFILE=ci eval $(atmos env)
GitHub Actions Integration
Write environment variables directly to GitHub Actions:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Atmos
uses: cloudposse/github-action-atmos@v2
- name: Export Atmos environment
run: atmos env --format github
- name: Use environment variables
run: |
echo "GitHub token available for private modules"
terraform init
The --format github option automatically writes to the $GITHUB_ENV file. You can also specify a custom output file:
# Write to custom file
atmos env --format github --output /tmp/my-env
# In GitHub Actions, use the default $GITHUB_ENV
atmos env --format github
Generate .env File
Create a .env file for tools that support it:
atmos env --format dotenv --output .env
JSON Output
Get environment variables as JSON for programmatic use:
atmos env --format json | jq .GITHUB_TOKEN
Output Formats
| Format | Output Example | Use Case |
|---|---|---|
bash (default) | export KEY='value' | Shell evaluation with eval $(atmos env) |
dotenv | KEY='value' | .env files for Docker, direnv, etc. |
json | {"KEY": "value"} | Programmatic consumption with jq, scripts |
github | KEY=value | GitHub Actions $GITHUB_ENV file |
Format Details
bash (default): Shell export statements with proper escaping for single quotes.
export GITHUB_TOKEN='ghp_xxxx'
export TF_PLUGIN_CACHE_DIR='/tmp/terraform-plugin-cache'
dotenv: Standard .env file format.
GITHUB_TOKEN='ghp_xxxx'
TF_PLUGIN_CACHE_DIR='/tmp/terraform-plugin-cache'
json: JSON object for programmatic use.
{
"GITHUB_TOKEN": "ghp_xxxx",
"TF_PLUGIN_CACHE_DIR": "/tmp/terraform-plugin-cache"
}
github: GitHub Actions environment file format. Multiline values use heredoc syntax.
GITHUB_TOKEN=ghp_xxxx
TF_PLUGIN_CACHE_DIR=/tmp/terraform-plugin-cache
Flags
--format,-fOutput format for the environment variables. Default:
bash.bash(default): Printsexport KEY='value'lines suitable for shell evaluationdotenv: PrintsKEY='value'lines in dotenv formatjson: Prints a JSON object of environment variablesgithub: PrintsKEY=valuelines for GitHub Actions$GITHUB_ENVfile
--output,-oOutput file path. When specified, writes to the file instead of stdout.
For
--format github, if--outputis not specified, the command reads theGITHUB_ENVenvironment variable and writes to that file. IfGITHUB_ENVis not set, an error is returned.For other formats, if
--outputis not specified, output goes to stdout.
Configuration
Environment variables are configured in the env section of atmos.yaml:
atmos.yaml
Configure Environment Variables
Learn how to define global environment variables in your atmos.yaml using static values, YAML functions, and shell expansion.
Notes
- Environment variables are sorted alphabetically in the output for deterministic results
- The
githubformat appends to the output file (doesn't overwrite), following GitHub Actions conventions - Shell escaping is applied for
bashanddotenvformats (single quotes with'escaped as'\'') - Profile merging happens automatically - use
--profileorATMOS_PROFILEto select a profile - This command only outputs global env from
atmos.yaml, not component-level env from stacks
See Also
- Environment Variables Configuration - Configure global environment variables
- Profiles - Environment-specific configuration overrides
- Stack Environment Variables - Component-level environment variables
atmos auth env- Export cloud provider credentials