Interpolation Syntax

Jaffle configuration supports interpolation syntax wrapped by ${}. You can get environment varialbes, call functions, and execute Python code in it:

Example:

${'hello'.upper()}

The above produces 'HELLO'.

Environment Variables

All environment variables consist of alphanumeric uppercase characters are available in the interpolation syntax.

Example:

${HOME}/etc

The above produces /home/your_account/etc if your HOME is '/home/your_account'.

If you need a default value for an environment variable, use env() function instead.

Variables

Defined variables can be embedded with ${var.name} syntax in arbitrary HCL value part.

Example:

disabled = "${var.enable_debug}"

See variable section for details.

Functions

env()

env(name, default='')[source]

Gets an environment variable.

Parameters:
  • name (str) – Environment variable name.
  • default (str) – Default value.
Returns:

env – Value of the environment variable.

Return type:

str

exec()

exec(command)[source]

Executes a command and returns the result of it.

Parameters:command (str) – Command name and arguments separated by whitespaces.
Returns:result – Result of the command.
Return type:str

fg()

fg(color)[source]

Inserts the escape sequence of the foreground color.

Available colors are ‘black’, ‘red’, ‘green’, ‘yellow’, ‘blue’, ‘magenta’, ‘cyan’, ‘white’, ‘bright_black’, ‘bright_red’, ‘bright_green’, ‘bright_yellow’, ‘bright_blue’ , ‘bright_magenta’, ‘bright_cyan’ and ‘bright_white’.

Parameters:color (str) – Foreground color in str (e.g. ‘red’).
Returns:seq – Escape sequence of the foreground color.
Return type:str
Raises:ValueError – Invalid color name.

bg()

bg(color)[source]

Inserts the escape sequence of the background color.

Available colors are ‘black’, ‘red’, ‘green’, ‘yellow’, ‘blue’, ‘magenta’, ‘cyan’, ‘white’, ‘bright_black’, ‘bright_red’, ‘bright_green’, ‘bright_yellow’, ‘bright_blue’ , ‘bright_magenta’, ‘bright_cyan’ and ‘bright_white’.

Parameters:color (str) – Background color in str (e.g. ‘red’).
Returns:seq – Escape sequence of the background color.
Return type:str
Raises:ValueError – Invalid color name.

reset()

reset()[source]

Inserts the escape sequence of display reeet.

Returns:seq – Escape sequence of display reeet.
Return type:str

jq_all()

jq_all(query, data_str, *args, **kwargs)[source]

Queries the nested data and returns all results as a list.

Parameters:data_str (str) – Nested data in Python dict’s representation format. If must be loadable by yaml.safe_load().
Returns:result – String representation of the result list.
Return type:str

pyjq processes the query. jq() is an alias to jq_all().

jq_first()

jq_first(query, data_str, *args, **kwargs)[source]

Queries the nested data and returns the first result.

Parameters:data_str (str) – Nested data in Python dict’s representation format. If must be loadable by yaml.safe_load().
Returns:result – String representation of the result object.
Return type:str

pyjq processes the query. jqf() is an alias to jq_first().

Filters

The | operator can be used in a ${} expression to apply filters.

Example:

${'hello world' | u}

The u filter applies URL escaping to the string, and produces 'hello+world'.

To apply more than one filter, separate them by a comma:

${'  hello world  ' | trim,u}

The above produces 'hello+world'.

Available Filters

u

URL escaping.

${"hello <b>world</b>" | x} => 'hello+world'

h

HTML escaping.

${"hello <b>world</b>" | x} => 'hello &lt;b&gt;world&lt;/b&gt;'

x

XML escaping.

${"hello <b>world</b>" | x} => 'hello &lt;b&gt;world&lt;/b&gt;'

trim

Whitespace trimming.

${"  hello world  " | x} => 'hello world'

entity

Produces HTML entity references for applicable strings.

${"→" | entit} => '&rarr;'