Skip to content
Latchkey

gomplate: Render Config From Datasources

gomplate renders a Go text/template and pulls values from named datasources such as env, files, or Vault.

gomplate is envsubst with a real template language and pluggable data. It is a single static binary, which makes it easy to pin in a pipeline.

What it does

gomplate reads a template with -f, evaluates Go template syntax plus its own function library, and writes the result with -o. Datasources declared with -d expose external data (files, env, http, vault, aws+sm) to the template via the ds function.

Common usage

Terminal
gomplate -f deploy.tmpl.yaml -o deploy.yaml
# a JSON datasource named "cfg"
gomplate -d cfg=./values.json -f deploy.tmpl.yaml -o deploy.yaml
# pull a value: {{ (ds "cfg").image }} inside the template

Options

FlagWhat it does
-f, --file <path>Input template file (use - for stdin)
-o, --out <path>Output file (default stdout)
-d, --datasource <alias=url>Register a named datasource
-c, --context <alias=url>Add a datasource to the . root context
-i, --in <string>Inline template string instead of -f
--input-dir / --output-dirRender a whole directory of templates

In CI

Pin the gomplate version (the function set changes between releases) and render into an artifact before kubectl apply so you can diff. Keep secrets out of the rendered file: read them from a vault or aws+sm datasource at deploy time rather than baking them into the output that lands in logs.

Common errors in CI

"error: template: <name>:N:M: executing ... at <ds "cfg">: error calling ds: datasource cfg not defined" means you referenced a datasource you never registered with -d. "map has no entry for key" surfaces as <no value> in output unless you set --missingkey error. "error: open deploy.tmpl.yaml: no such file or directory" is a path relative to the wrong working directory in the job.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →