tplenv 0.3.0

Render template placeholders from environment variables and YAML values files
tplenv-0.3.0 is not a library.

tplenv

tplenv renders {{...}} placeholders in a template file.

  • {{VARNAME}} reads from environment variables (or from environment.VARNAME with --value-file-only).
  • {{ .Values.key }} reads from a YAML values file.

Install

To install tplenv on your computer, just run:

cargo install --path .

Building

cargo build --release

Binary path:

./target/release/tplenv

Help

Show CLI usage:

tplenv --help

Usage

tplenv --file INPUT.yaml [--values Values.yaml] [--output OUTPUT.yaml] [--value-file-only]

Options:

  • -f, --file <PATH>: input template file (required)
  • --values <PATH>: values YAML file (default: Values.yaml)
  • -o, --output <PATH>: output file (- or omitted means stdout)
  • -v, --verbose: print substitutions to stderr
  • --create-values-file: ask for missing .Values.* placeholders and write/update the values file
  • --force: only valid with --create-values-file; asks for all .Values.* placeholders and uses existing values as prompt defaults
  • --value-file-only: resolve {{VARNAME}} from environment.VARNAME in the values file (do not read OS environment variables)
  • -h, --help: print help
  • --version: print version

Examples

Render using environment variables and values file:

tplenv --file deployment.tpl.yaml --values Values.yaml --output deployment.yaml

Create/update only missing values in Values.yaml, then render:

tplenv --file deployment.tpl.yaml --create-values-file

Ask for all values found in the template and prefill from existing file values:

tplenv --file deployment.tpl.yaml --create-values-file --force

Resolve {{VARNAME}} from the values file:

tplenv --file deployment.tpl.yaml --values Values.yaml --value-file-only

With --value-file-only, interactive mode also manages missing environment.* keys:

tplenv --file deployment.tpl.yaml --values Values.yaml --value-file-only --create-values-file

More runnable examples are in examples/README.md. That includes a --value-file-only --create-values-file --force interactive example with defaults.

Tests

Run unit tests:

cargo test

Nix (Deterministic Build)

This repo now includes a flake-based build:

  • /Users/christoffetzer/Library/Mobile Documents/com~apple~CloudDocs/GIT/scontainug/tplenv/flake.nix
  • /Users/christoffetzer/Library/Mobile Documents/com~apple~CloudDocs/GIT/scontainug/tplenv/default.nix

Build with Nix:

nix build .#tplenv

Enter development shell:

nix develop

For deterministic builds across machines, commit flake.lock to the repo. If it does not exist yet, generate it once with:

nix flake lock