Stein Documentations

A linter for config files with a customizable rule set

Interpolation Syntax

Embedded within strings in Terraform, whether you’re using the Terraform syntax or JSON syntax, you can interpolate other values. These interpolations are wrapped in ${}, such as ${}.

The interpolation syntax is powerful and allows you to reference variables, attributes of resources, call functions, etc.

You can perform simple math in interpolations, allowing you to write conditions such as ${count.index + 1}. And you can also use conditionals to determine a value based on some logic.

You can escape interpolation with double dollar signs: $${foo} will be rendered as a literal ${foo}.

Available Variables

There are a variety of available variable references you can use.

User string variables

Use the var.prefix followed by the variable name. For example, ${} will interpolate the foo variable value.

User map variables

The syntax is var.MAP["KEY"]. For example, ${var.amis["us-east-1"]} would get the value of the us-east-1 key within the amis map variable.

User list variables

The syntax is "${var.LIST}". For example, "${var.subnets}" would get the value of the subnets list, as a list. You can also return list elements by index: ${var.subnets[idx]}.

Path information


The syntax is path.TYPE. TYPE can be file, dir, or policies. cwd will interpolate the current working directory. module will interpolate the path to the current module. root will interpolate the path of the root module. In general, you probably want the path.module variable.

# => manifests/microservices/x-gateway-jp/development/Service/a.yaml
# [Notes]
#  this variable is an alias of `filename` variable

# => manifests/microservices/x-gateway-jp/development/Service

Predefined variables

  • filename: Filename to be applied policy (alias of path.policy)

Environment variables information

The syntax is env.ENV. ENV can be USER, HOME, etc. These values comes from env command output.

# => /home/username

# => vim


Interpolations may contain conditionals to branch on the final value.

"${var.user == "john" ? var.member : env.anonymous}"

# => var.member (if var.user is john)
# => var.anonymous (if var.user is not john)

The conditional syntax is the well-known ternary operation:


The condition can be any valid interpolation syntax, such as variable access, a function call, or even another conditional. The true and false value can also be any valid interpolation syntax. The returned types by the true and false side must be the same.

The supported operators are:

  • Equality: == and !=
  • Numerical comparison: >, <, >=, <=
  • Boolean logic: &&, ||, unary !

Built-in Functions

Stein ships with built-in functions. Functions are called with the syntax name(arg, arg2, ...). For example, to read a file: ${file("path.txt")}.

Stein supports all Terraform’s built-in functions listed in this page.

In addition to these functions, it also comes with the original built-in functions to make it even easier to write rules.


Returns the files matched by given pattern


  • input args: string
  • return values: list of string


# => ["a.txt", "b.txt", "c.txt"]


Returns the file path shortened like Vim’s one.


  • input args: string
  • return values: string


# => "m/m/x/d/S/a.yaml"


Returns the file extensions.


  • input args: string
  • return values: string


# => ".txt"

wc(text, ["l", "w", "c"])

Returns the counted number of text as options (lines, words, chars). Default option is lines.


  • input args: string, string… (Optional)
  • return values: number


"${wc("foo\nbar baz")}"
# => 2

"${wc("foo\nbar baz", "c")}"
# => 9

"${wc("foo\nbar baz", "w")}"
# => 3

grep(text, pattern)

Returns the text block matched with the given pattern.


  • input args: string
  • return values: string


My life didn't please me,
so I created my life.
- Coco Chanel
"${grep(file("text.txt"), "life")}"
# => "My life didn't please me,\nso I created my life."

lookuplist(map, key)

Returns a list matched by the key in the given map.

Like the Terraform’s lookup but this is only for returning a list.


  • input args: map, string
  • return values: list of string


variable "colors" {
  type = "map"

  default = {
    "red" = [
    "blue" = [
      "cerulean blue",
      "turquoise blue",
"${lookuplist(var.colors, "red")}"
# => ["burgundy", "terracotta", "scarlet"]

"${contains(lookuplist(var.colors, "red"), "scarlet")}"
# => true

match(pattern, text)

Returns a true if the text is matched with the pattern.


  • input args: string, string
  • return values: boolean


"${match("abcdef", "^a")}"
# => true

color(str, attrs...)

Returns a string colorized by the color name.


  • input args: string, string
  • return values: string


"${color("hello!", "white")}"
# => "\x1b[37mhello!\x1b[0m"

"${color("hello!", "red", "BgBlack")}"
# => "\x1b[31m\x1b[40mhello!\x1b[0m"


Returns true if path exists


  • input args: string
  • return values: boolean


# => true (if exists)

jsonpath(query, default...)


Custom Functions

While supporting some useful built-in functions, Stein allows to create user-defined functions.

function "add" {
  params = [a, b]
  result = a + b
"${add(1, 3)}"
# => 4

For more details, please see also Custom Functions


Almost the same as Terraform Math mechanism.

Last updated on 17 Jan 2019 / Published on 17 Jan 2019
Edit on GitHub