Skip to content

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.

Templates use shell-style variable expansion:

  • ${VAR} - Expands to the value of VAR
  • $VAR - Also valid, but braces are recommended for clarity

If a referenced variable is not defined, the job will fail with an error.

The following variables are always available:

VariableDescriptionExample
JOB_NAMEThe job name from metadata.namemy-collection-job
JOB_DATE_ISO8601Current UTC timestamp in ISO8601 basic format (URL-safe)20240115T143052Z
JOB_DATE_RFC3339Current UTC timestamp in RFC3339 format2024-01-15T14:30:52Z

Additional environment variables can be made available using the --pass-env flag:

Terminal window
infracollect collect job.yaml --pass-env AWS_REGION --pass-env ENVIRONMENT

Only 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):

Terminal window
infracollect collect job.yaml --pass-all-env
apiVersion: v1
kind: CollectJob
metadata:
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:

Terminal window
infracollect collect job.yaml --pass-env API_USER --pass-env API_PASSWORD

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]string fields (e.g., headers, params)
  • All elements in []string (string array) fields marked with the template tag (e.g., program)

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.