You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/functions/yaml/env.mdx
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,11 @@ The `env:` section follows the standard Atmos merge priority:
80
80
This means values defined at the component level will override values from globals.
81
81
:::
82
82
83
+
:::note Type-Aware Merging
84
+
Atmos supports type-aware merging of YAML functions and concrete values, allowing them to coexist in the inheritance chain without type conflicts.
85
+
See the full explanation: [YAML Function Merging](/reference/yaml-function-merging)
86
+
:::
87
+
83
88
## Limitations
84
89
85
90
**Single-Pass Processing**: YAML functions are processed in a single pass. This means `!env` cannot reference environment variables that are defined by other YAML functions in the same component section.
Copy file name to clipboardExpand all lines: website/docs/functions/yaml/terraform.state.mdx
+41-2Lines changed: 41 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,6 +67,11 @@ Atmos processes the templates first, and then executes the `!terraform.state` fu
67
67
the function dynamically.
68
68
:::
69
69
70
+
:::note Type-Aware Merging
71
+
Atmos supports type-aware merging of YAML functions and concrete values, allowing them to coexist in the inheritance chain without type conflicts.
72
+
See the full explanation: [YAML Function Merging](/reference/yaml-function-merging)
73
+
:::
74
+
70
75
## `!terraform.state` Function Execution Flow
71
76
72
77
When processing the `!terraform.state` YAML function for a component in a stack, Atmos executes the following steps:
@@ -128,7 +133,40 @@ For more details, review the following docs:
128
133
129
134
## Handling YQ Expressions with Bracket Notation and Quotes
130
135
131
-
`!terraform.state` shares the same parser as `!terraform.output`, so the quoting rules are identical. When you need double quotes inside a YQ expression (for example, to reference `["github-dependabot"]`), wrap the entire expression in single quotes. Refer to the [!terraform.output guidance](/functions/yaml/terraform.output#handling-yq-expressions-with-bracket-notation-and-quotes) for detailed examples and escape rules.
136
+
When you access map keys that contain special characters (such as hyphens) by using YQ bracket notation, you must wrap the key in double quotes like `["github-dependabot"]`. This often clashes with the surrounding quotes that protect the entire expression in YAML.
137
+
138
+
To avoid conflicting quotes, wrap the entire YQ expression in single quotes while keeping the double quotes inside the brackets:
139
+
140
+
```yaml
141
+
# Use single quotes around the expression to allow double quotes inside brackets
- Wrap the entire YQ expression in single quotes when it contains double quotes.
164
+
- Use double quotes inside brackets for string keys in YQ expressions.
165
+
- If you need single quotes inside the expression, escape them by doubling: `''`.
166
+
167
+
:::tip
168
+
This quoting pattern works for every Atmos YAML function that accepts YQ expressions, including [!terraform.output](/functions/yaml/terraform.output) and [!include](/functions/yaml/include).
169
+
:::
132
170
133
171
## Using YQ Expressions to provide a default value
134
172
@@ -483,4 +521,5 @@ vars:
483
521
484
522
- Be mindful of disaster recovery (DR) implications when using it across regions.
485
523
486
-
- Consider cold-start scenarios: if the dependent component has not yet been provisioned, `terraform output` will fail.
524
+
- Consider cold-start scenarios: if the referenced component's state file doesn't exist (e.g., not yet provisioned), `!terraform.state` returns `null`.
525
+
Use the YQ `//` operator to provide default values for components that may not be provisioned yet (see [Using YQ Expressions to provide a default value](#using-yq-expressions-to-provide-a-default-value)).
description: How Atmos handles merging YAML functions with concrete values in the inheritance chain
6
+
---
7
+
8
+
importIntrofrom'@site/src/components/Intro'
9
+
10
+
<Intro>
11
+
Atmos supports type-aware merging of YAML functions and concrete values, allowing them to coexist in the inheritance chain without type conflicts.
12
+
</Intro>
13
+
14
+
## The Problem: Type Conflicts During Merge
15
+
16
+
When merging stack configurations, Atmos needs to handle both concrete values and YAML function references. Without special handling, the merge process would encounter type mismatches:
17
+
18
+
```yaml
19
+
# Base catalog (catalog/app/defaults.yaml)
20
+
components:
21
+
terraform:
22
+
my-app:
23
+
vars:
24
+
database_url: "postgresql://localhost:5432/mydb"# Concrete string value
25
+
26
+
# Environment override (stacks/prod/app.yaml)
27
+
components:
28
+
terraform:
29
+
my-app:
30
+
vars:
31
+
database_url: !env DATABASE_URL # YAML function reference
32
+
```
33
+
34
+
The YAML function `!env DATABASE_URL` is a different type than the string `"postgresql://localhost:5432/mydb"`. Without special handling, merging these would cause a type conflict error.
35
+
36
+
## The Solution: Type-Aware Merging
37
+
38
+
Atmos handles this gracefully through **type-aware merging**:
39
+
40
+
1. YAML functions are recognized and wrapped in a special type during parsing
41
+
2. During merge, this allows YAML functions to replace concrete values (and vice versa) without type errors
42
+
3. YAML functions are evaluated as the final step in stack processing, as they have always been
43
+
44
+
This approach ensures that YAML functions can override static values throughout the inheritance chain.
45
+
46
+
## Supported Functions
47
+
48
+
The following YAML functions support type-aware merging:
In this example, the production stack overrides static defaults with YAML functions. Type-aware merging allows these different value types to coexist without errors.
0 commit comments