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/resource-query-files.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -279,9 +279,50 @@ AND project = '{{ project }}'
279
279
AND zone ='{{ zone }}'
280
280
```
281
281
282
+
## Special Variables
283
+
284
+
In addition to the properties defined in the manifest, StackQL Deploy injects a set of built-in variables into every template context automatically.
285
+
286
+
| Variable | Scope | Description |
287
+
|---|---|---|
288
+
|`stack_name`| Global | Name of the stack as declared in the manifest |
289
+
|`stack_env`| Global | Environment name supplied to the CLI (`dev`, `prd`, etc.) |
290
+
|`resource_name`| Per-resource | Name of the resource currently being processed |
291
+
|`idempotency_token`| Per-resource | Stable UUID v4 for this resource for the lifetime of the session |
292
+
|`this.idempotency_token`| Per-resource (inside `.iql`) | Preferred alias — expands to `{{ <resource_name>.idempotency_token }}`|
293
+
|`<resource_name>.idempotency_token`| Global | Scoped form, usable in any downstream resource |
294
+
295
+
### `idempotency_token`
296
+
297
+
`idempotency_token` is generated once per resource at session start and stays constant for all retries within that run. Many providers (for example the AWS Cloud Control API) accept a client-side token to identify whether a request is a genuine new operation or a retry of an earlier one — `idempotency_token` is designed exactly for that purpose.
298
+
299
+
```sql
300
+
/*+ create */
301
+
INSERT INTOawscc.cloudformation.stacks(
302
+
StackName,
303
+
TemplateURL,
304
+
ClientRequestToken,
305
+
region
306
+
)
307
+
SELECT
308
+
'{{ stack_name }}-{{ stack_env }}',
309
+
'{{ template_url }}',
310
+
'{{ this.idempotency_token }}',
311
+
'{{ region }}'
312
+
RETURNING *
313
+
```
314
+
315
+
:::tip
316
+
317
+
Use `{{ this.idempotency_token }}` (which expands to `{{ <resource_name>.idempotency_token }}`) when writing queries inside a resource's own `.iql` file. Use `{{ <resource_name>.idempotency_token }}` to access another resource's token from a downstream resource.
318
+
319
+
Unlike `{{ uuid() }}`, which generates a **new** UUID on every render, `idempotency_token` is stable for the entire session, making it safe to include in queries that may be retried.
320
+
321
+
:::
322
+
282
323
## Template Filters
283
324
284
-
StackQL Deploy uses a Jinja2-compatible templating engine and extends it with custom filters for infrastructure provisioning. For a complete reference of all available filters, see the [__Template Filters__](template-filters) documentation.
325
+
StackQL Deploy uses a Jinja2-compatible templating engine and extends it with custom filters for infrastructure provisioning. For a complete reference of all available filters and special variables, see the [__Template Filters__](template-filters) documentation.
A UUID v4 that is generated **once per resource per session (invocation)** and remains stable for the lifetime of that run. This is particularly important for asynchronous mutation operations where a provider needs to reliably distinguish a genuine new request from a retry of an earlier request.
182
+
183
+
| Access form | Where available |
184
+
|---|---|
185
+
|`{{ idempotency_token }}`| Inside the resource's own `.iql` file |
186
+
|`{{ this.idempotency_token }}`| Inside the resource's own `.iql` file (preferred, explicit) |
187
+
|`{{ <resource_name>.idempotency_token }}`| In any downstream resource template |
188
+
189
+
**Example — passing a client token to AWS Cloud Control API:**
190
+
191
+
```sql
192
+
/*+ create */
193
+
INSERT INTOawscc.cloudformation.stacks(
194
+
StackName,
195
+
TemplateURL,
196
+
ClientRequestToken,
197
+
region
198
+
)
199
+
SELECT
200
+
'{{ stack_name }}-{{ stack_env }}',
201
+
'{{ template_url }}',
202
+
'{{ this.idempotency_token }}',
203
+
'{{ region }}'
204
+
RETURNING *
205
+
```
206
+
207
+
**Example — referencing another resource's token from a downstream resource:**
SELECT'{{ my_upstream_resource.idempotency_token }}', '{{ region }}'
213
+
```
214
+
215
+
:::note
216
+
217
+
`{{ uuid() }}` (see below) generates a **new** UUID on every template render, so retrying the same query produces a different value each time. Use `{{ this.idempotency_token }}` instead when you need a stable, retry-safe identifier.
0 commit comments