YAML Configuration Reference
YAML is the configuration language for Atmos stacks. Understanding YAML's features, gotchas, and best practices is essential for writing maintainable stack configurations at scale.
This guide covers everything you need to know about YAML in Atmos, from anchors and references to avoiding common pitfalls when mixing YAML with Go templates.
YAML is a Superset of JSON
Any valid JSON is also valid YAML. This means you can embed JSON objects anywhere in your YAML configuration:
stacks/prod.yaml
When to use JSON in YAML:
- ✅ Compact, single-line objects
- ✅ Generated configuration from scripts
- ✅ Copying from JSON sources
When to use YAML syntax:
- ✅ Multi-line configuration (more readable)
- ✅ Configuration that needs comments
- ✅ Nested structures (cleaner indentation)
Dot Notation for Nested Keys
When you only need to set a single value deep in a nested structure, you can use dot notation instead of creating the full hierarchy. This makes your configuration more concise and readable.
Traditional Nesting vs Dot Notation
Traditional approach (verbose):
stacks/prod.yaml
Dot notation (concise):
stacks/prod.yaml
Both configurations produce the exact same result. Dot notation is purely a syntax convenience for writing cleaner YAML.
Mixing Dot Notation and Traditional Nesting
You can mix both approaches in the same configuration. Use dot notation for single values, traditional nesting for groups:
stacks/prod.yaml
When to Use Dot Notation
✅ Use dot notation when:
- Setting a single value deep in the tree
- You want more concise, readable configuration
- The nested path is clear and self-documenting
❌ Use traditional nesting when:
- Setting multiple related values in the same section
- You want to emphasize the structure
- You're defining complex nested objects with many fields
Dot Notation Works Everywhere
Dot notation isn't limited to component configuration—it works in any YAML section:
stacks/globals.yaml
This is equivalent to:
stacks/globals.yaml
Use dot notation when it improves readability. If you have 2+ values in the same section, traditional nesting is often clearer.
Anchors and References (Aliases)
YAML anchors (&) and references (*) let you reuse configuration within a single file. This is YAML's built-in DRY mechanism.
Basic Anchor and Reference
stacks/prod.yaml
Result after YAML processing:
components:
terraform:
vpc:
vars:
tags:
ManagedBy: Atmos
Environment: production
Team: Platform
eks:
vars:
tags:
ManagedBy: Atmos
Environment: production
Team: Platform
Merging with << (Merge Key)
The merge key << combines anchors with additional keys:
stacks/prod.yaml
Result:
components:
terraform:
vpc:
vars:
tags:
ManagedBy: Atmos
Environment: production
Name: prod-vpc
Type: network
Real-World Example: Component Defaults
stacks/prod-us-east-1.yaml
For cross-file reuse, use Atmos imports and inheritance instead of YAML anchors.
Multiple Anchors with Merge
You can merge multiple anchors:
stacks/prod.yaml
Result:
tags:
Compliance: SOC2
DataClassification: sensitive
CostCenter: engineering
Project: infrastructure
Name: prod-database
Anchors are file-scoped only. They don't work across imports. Use Atmos imports and inheritance for cross-file reuse.
Type Coercion Gotchas
YAML automatically converts values based on their appearance. This causes unexpected behavior if you're not careful.
The NO Problem (Country Codes)
stacks/countries.yaml (WRONG)
What YAML sees:
vars:
allowed_countries:
- US
- GB
- false # NO became false!
- SE
- DK
Fix: Quote it
stacks/countries.yaml (CORRECT)
Boolean Conversion Table
YAML interprets these as booleans:
| String | Becomes |
|---|---|
yes, Yes, YES | true |
no, No, NO | false |
true, True, TRUE | true |
false, False, FALSE | false |
on, On, ON | true |
off, Off, OFF | false |
Always quote these if you need them as strings:
stacks/config.yaml
Numeric Type Coercion
stacks/config.yaml
Octal Number Trap
stacks/config.yaml
Quoting Best Practices
When You MUST Quote
1. Strings that look like other types:
vars:
country: "NO" # Looks like boolean
version: "1.20" # Looks like number
value: "true" # Looks like boolean
code: "07094" # Leading zero
2. Strings with special characters:
vars:
url: "https://example.com" # Contains :
path: "/var/log/app.log" # Fine, but quote for safety
regex: "^[a-z]+$" # Contains special chars
template: "{{ .vars.name }}" # Contains braces
3. Multi-line strings (see next section)
Consistent Quoting Strategy
Recommended: Quote all string values for consistency
stacks/prod.yaml (Consistent Style)
Benefits:
- ✅ No mental overhead deciding when to quote
- ✅ Prevents type coercion surprises
- ✅ Easier to read and maintain
- ✅ Tools like prettier/yamllint can enforce it
Multi-Line Strings
YAML has multiple ways to handle multi-line strings. Choose the right one for your use case.
Literal Block Scalar (|)
Preserves line breaks and trailing newline:
stacks/config.yaml
Result:
#!/bin/bash\nset -e\necho "Starting deployment"\nterraform apply -auto-approve\n
Folded Block Scalar (>)
Folds lines into a single line, preserves final newline:
stacks/config.yaml
Result:
This is a very long description that spans multiple lines but will be folded into a single line when processed.\n
Block Chomping (Control Trailing Newlines)
| or > alone: Keep final newline
|- or >-: Strip final newline (clip)
|+ or >+: Keep all trailing newlines (keep)
stacks/config.yaml
Real-World Example: User Data Script
stacks/prod.yaml
Go Templates in YAML (Gotchas!)
Atmos uses Go templates for dynamic configuration. Go template braces conflict with YAML flow-style maps.
The Brace Problem
stacks/config.yaml (WRONG)
Error:
Error parsing YAML: mapping values are not allowed in this context
Solution: Quote Template Strings
stacks/config.yaml (CORRECT)
Template Delimiters and YAML Conflicts
Problem: YAML flow-style syntax looks like templates:
stacks/config.yaml
Best practice: Avoid flow-style maps when using templates
stacks/config.yaml (Better)
Nested Templates in Lists
stacks/prod.yaml
Common YAML Gotchas
1. Indentation Matters (2 Spaces Standard)
WRONG: Mixed indentation
CORRECT: Consistent 2-space indentation
Best practice:
- ✅ Use 2 spaces (Atmos convention)
- ✅ Configure editor to insert spaces for Tab
- ✅ Never mix tabs and spaces
- ✅ Use
.editorconfigto enforce (see EditorConfig Validation)
2. Colons in Unquoted Strings
WRONG
CORRECT
3. Lists vs Maps
stacks/config.yaml
In Atmos, this matters for deep merge:
- Maps merge recursively
- Lists replace entirely
4. Empty Values
stacks/config.yaml
5. Duplicate Keys (Last Wins)
stacks/config.yaml
Result: environment: prod
Best practice: Use linters to detect duplicates (see YAML Schema Validation)
Best Practices for Maintainable YAML
1. Consistent Quoting
stacks/prod.yaml
2. Use Block Style for Nested Data
stacks/prod.yaml
3. Leverage Comments
stacks/prod.yaml
4. Use Anchors for Repeated Config (Within File)
stacks/prod.yaml
5. Separate Concerns with Imports (Across Files)
stacks/_defaults/tags.yaml
stacks/prod.yaml
6. Use YAML Schema Validation
Configure JSON Schema validation to catch errors:
atmos.yaml
See JSON Schema Validation for details.
7. Validate YAML with EditorConfig
Use .editorconfig to enforce consistent formatting:
.editorconfig
See EditorConfig Validation for details.
YAML Linting Tools
Use linters to catch issues early:
yamllint - General YAML linting
# Install
pip install yamllint
# Lint stacks
yamllint stacks/
Atmos Validation - Schema and policy validation
# Validate stack configurations
atmos validate stacks
# Validate specific component
atmos validate component vpc -s prod
See Validation for comprehensive validation strategies.
Quick Reference: YAML in Atmos
| Feature | Syntax | Use Case |
|---|---|---|
| Anchor | &name | Define reusable config within file |
| Reference | *name | Reuse anchored config |
| Merge | <<: *name | Combine anchor with new keys |
| Literal Block | | | Multi-line string, preserve newlines |
| Folded Block | > | Multi-line string, fold to single line |
| Quote Strings | "string" | Prevent type coercion, escape special chars |
| Go Template | "{{ .vars.x }}" | Dynamic values (MUST quote) |
| JSON in YAML | {"key": "val"} | Compact objects (use sparingly) |
| Comment | # comment | Document configuration |
Key Takeaways
- Quote all string values - Prevents type coercion surprises
- Quote Go templates - Avoids YAML parsing conflicts with braces
- Use 2-space indentation - Atmos standard, configure your editor
- Leverage anchors within files - Use imports across files
- Prefer block style over flow style - More readable and commentable
- Validate early and often - Use schema validation and linters
- YAML is JSON-compatible - But prefer YAML syntax for readability
- Watch for
NO,ON,OFF- Country codes and words that become booleans
See Also
- YAML in Atmos (Learn) - Beginner-friendly YAML basics
- Stack Configuration - Advanced stack configuration
- Template Functions - Go template functions in Atmos
- YAML Functions - Native YAML tag functions
- JSON Schema Validation - Validate YAML structure
- EditorConfig Validation - Enforce formatting