Templates
Template expansion allows you to use dynamic values in your job configuration files. Fields that support templating can reference variables using the ${VAR} syntax.
Syntax
Section titled “Syntax”Templates use shell-style variable expansion:
${VAR}- Expands to the value ofVAR$VAR- Also valid, but braces are recommended for clarity
If a referenced variable is not defined, the job will fail with an error.
Built-in Variables
Section titled “Built-in Variables”The following variables are always available:
| Variable | Description | Example |
|---|---|---|
JOB_NAME | The job name from metadata.name | my-collection-job |
JOB_DATE_ISO8601 | Current UTC timestamp in ISO8601 basic format (URL-safe) | 20240115T143052Z |
JOB_DATE_RFC3339 | Current UTC timestamp in RFC3339 format | 2024-01-15T14:30:52Z |
Environment Variables
Section titled “Environment Variables”Additional environment variables can be made available using the --pass-env flag:
infracollect collect job.yaml --pass-env AWS_REGION --pass-env ENVIRONMENTOnly explicitly passed environment variables can be referenced. If a passed variable is not set in the environment, the job will fail.
To pass all environment variables (use with caution in trusted environments):
infracollect collect job.yaml --pass-all-envExample
Section titled “Example”apiVersion: v1kind: CollectJobmetadata: name: daily-backup
spec: collectors: - id: api http: base_url: https://api.example.com auth: basic: username: ${API_USER} password: ${API_PASSWORD}
steps: - id: data collector: api http_get: path: /export
output: sink: s3: bucket: my-backups prefix: ${JOB_NAME}/${JOB_DATE_ISO8601}/Run with:
infracollect collect job.yaml --pass-env API_USER --pass-env API_PASSWORDSupported Fields
Section titled “Supported Fields”Not all fields support template expansion. Fields that support templates are marked with a Template badge in the reference documentation. Generally, string fields that accept user-provided values (paths, URLs, credentials, prefixes) support templating.
The following field types are expanded:
- String fields marked with the template tag
- All values in
map[string]stringfields (e.g.,headers,params) - All elements in
[]string(string array) fields marked with the template tag (e.g.,program)
Array Templating Example
Section titled “Array Templating Example”String arrays support per-element template expansion. For example, in an exec step:
steps: - id: run-script exec: program: - /bin/bash - -c - echo "Job ${JOB_NAME} running in ${ENVIRONMENT}"Each element in the program array is expanded independently, allowing you to use variables in command arguments.