Injecting Values
Sometimes it might be required to pass externally acquired data into Jsonnet.
There are three ways of doing so:
Also check out the official Jsonnet docs on this topic.
JSON files
Jsonnet is a superset of JSON, it treats any JSON as valid Jsonnet. Because many systems can be told to output their data in JSON format, this provides a pretty good interface between those.
For example, your build tooling like make
could acquire secrets from systems such as
Vault, etc. and write that into secrets.json
.
External variables
Another way of passing values from the outside are external variables, which are specified like so:
They can be accessed using std.extVar
and the name given to them on the command line:
Top Level Arguments
Usually with Tanka, your main.jsonnet
holds an object at the top level (most
outer type in the generated JSON):
Another type of Jsonnet that naturally accepts parameters is the function
.
When the Jsonnet compiler finds a function at the top level, it invokes it and
allows passing parameter values from the command line:
Here, who
needs a value while msg
has a default. This can be invoked like so: