Atmos YAML Functions
YAML Functions are the recommended way to add dynamic behavior to your Atmos configurations. They are native YAML features that work with the YAML parser, making them type-safe, predictable, and error-resistant. Unlike template functions which manipulate raw text, YAML functions operate on structured data after parsing.
Why YAML Functions Are Safer
YAML functions are based on YAML Explicit typing and user-defined Explicit Tags (local data types). Explicit tags are denoted by the exclamation point ("!") symbol.
Key advantages over template functions:
- Cannot break YAML syntax - Functions execute after YAML parsing, not before
- Type-safe - Work with actual YAML types, not raw strings
- No indentation issues - The YAML structure is already established
- Clear error messages - Errors point to specific YAML nodes, not parsing failures
- Predictable behavior - Always return valid YAML data structures
Atmos detects the tags in the stack manifests and executes the corresponding functions.
YAML supports three types of data: core, defined, and user-defined.
- Core types: Universally supported, including floats, integers, strings, lists, and maps.
- Defined types: Advanced types like binary data, specified in the YAML standard but not always supported.
- User-defined types: Custom extensions for classes, structures, and functions. Atmos leverages user-defined types to implement its custom functions and extend YAML's capabilities.
Use-cases
-
The
!terraform.outputYAML function allows you to access component outputs (remote state) directly within Atmos stack manifests. Note that this requires initializing each component (terraform/tofu init), which initializes all Terraform/OpenTofu modules and downloads all Terraform/OpenTofu providers, which may significantly impact performance. Consider using!storeor!terraform.statefunctions instead, which don't have this performance penalty. -
The
!terraform.stateYAML function reads outputs directly from the configured Terraform or OpenTofu backend, without initializing providers or running Terraform — it's very fast and currently supports S3 and local backends for accessing remote state. -
The
!storeYAML function allows reading the values from a remote store (e.g. SSM Parameter Store, Artifactory, etc.) into Atmos stack manifests -
The
!store.getYAML function allows retrieving arbitrary keys directly from a store without following the Atmos stack/component/key naming convention. This is useful for accessing values stored by external systems or for retrieving global configuration that doesn't belong to a specific component -
The
!includeYAML function allows downloading local or remote files from different sources, and assigning the file contents or individual values to the sections in Atmos stack manifests -
The
!templateYAML function is designed to evaluate and inject outputs containing maps or lists into the YAML document, whether generated by theatmos.Componenttemplate function or any Go template. -
The
!execYAML function is used to execute shell scripts and assign the results to the sections in Atmos stack manifests -
The
!envYAML function is used to retrieve environment variables and assign them to the sections in Atmos stack manifests -
The
!repo-rootYAML function is used to retrieve the root directory of the Atmos repository
You can combine Atmos Stack Manifest Templating with Atmos YAML functions within the same stack configuration. Atmos processes templates first, followed by YAML functions, enabling you to dynamically provide parameters to the YAML functions.
Atmos sections supporting YAML functions
You can use the YAML functions in all Atmos stack manifest sections:
varssettingsenvmetadatacommandcomponentprovidersoverridesbackendbackend_typeremote_state_backendremote_state_backend_type
Examples
stack.yaml
Native Atmos YAML Functions
Atmos natively supports the following YAML functions:
📄️ !terraform.output
Read the remote state of any Atmos component from Terraform/OpenTofu outputs
📄️ !terraform.state
The FASTEST way to retrieve Terraform outputs - reads directly from state backends without initializing Terraform or downloading providers
📄️ !store
Read a value from a store for an Atmos component in a stack
📄️ !store.get
Retrieve arbitrary keys directly from a store
📄️ !env
Retrieve environment variables and assign them to the sections in Atmos stack manifests
📄️ !exec
Execute shell scripts and assign the results to the sections in Atmos stack manifests
📄️ !include
Download local or remote files from different sources, and insert their contents or specific values directly into sections of your stack manifests
📄️ !include.raw
Force inclusion of files as raw strings regardless of their extension or content
📄️ !template
Handle outputs containing maps or lists returned from the atmos.Component template function
📄️ !repo-root
Get the root directory of the Atmos repository