From 6574717c55ec352f76d3da41fdbaed7f6e96572f Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 12 Sep 2022 16:36:18 -0400 Subject: [PATCH] docs: update `template` for Nomad Variables (#14527) --- .../docs/job-specification/template.mdx | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/website/content/docs/job-specification/template.mdx b/website/content/docs/job-specification/template.mdx index 59bcb005d..ef39411fa 100644 --- a/website/content/docs/job-specification/template.mdx +++ b/website/content/docs/job-specification/template.mdx @@ -365,6 +365,176 @@ EOH } ``` +### Nomad Variables + +Nomad [variables] can be queried using the `nomadVar`, `nomadVarList`, +`nomadVarListSafe`, and `nomadVarExists` functions. + +#### `nomadVarList` and `nomadVarListSafe` + +These functions can be used to list the paths of Nomad variables available to +the task based on its [workload identity]. You can provide an optional prefix to +filter the path list by as a parameter. + +The list functions return a slice of `NomadVarMeta` type: + +```golang +type NomadVarMeta struct { + Namespace, Path string + CreateIndex, ModifyIndex uint64 + CreateTime, ModifyTime nanoTime +} +``` + +The `nanoTime` type contains Unix nanoseconds since the epoch. Its string method +prints it out as a formatted date/time value. It also has a `Time` method that +can be used to retrieve a Go [`time.Time`] for further manipulation. + +`NomadVarMeta` objects print their `Path` value when used as a string. For +example, these two template blocks produce identical output: + +```hcl +template { + data = <