YAML Functions in Locals
· 2 min read
Locals now support YAML functions like !env, !exec, !store, !terraform.state, and !terraform.output.
The Feature
Locals can now use all Atmos YAML functions to fetch dynamic values:
!env- Environment variables!exec- Command execution!store- Store lookups!terraform.state- Terraform state queries!terraform.output- Terraform outputs from other components
Example with Environment Variables
locals:
api_endpoint: !env API_ENDPOINT
api_url: "https://{{ .locals.api_endpoint }}/api/v1"
components:
terraform:
myapp:
vars:
api_url: "{{ .locals.api_url }}"
Example with Terraform State
locals:
# Fetch from another component's terraform state
vpc_id: !terraform.state vpc .vpc_id
subnet_ids: !terraform.state vpc .private_subnet_ids
components:
terraform:
eks:
vars:
vpc_id: "{{ .locals.vpc_id }}"
subnet_ids: "{{ .locals.subnet_ids }}"
Example with Store
locals:
db_password: !store secrets/database .password
connection_string: "postgresql://app:{{ .locals.db_password }}@db.example.com/mydb"
components:
terraform:
backend:
vars:
database_url: "{{ .locals.connection_string }}"
How It Works
- YAML functions in locals are processed during stack configuration loading
- The resolved values are available to other locals and component vars
- Locals can combine YAML function results with Go templates
Use Cases
- Environment-specific configuration: Use
!envto inject environment-specific values - Cross-component references: Use
!terraform.stateto reference outputs from other components - Secret management: Use
!storeto fetch secrets from your configured store - Dynamic values: Use
!execto run commands and capture output
Upgrade
Upgrade Atmos to get this feature. Existing locals configurations continue to work unchanged.
