Documentation

Every attribute value in a profile is an HCL expression, so you get interpolation, for comprehensions and a small function library for free. The functions are thin wrappers around the go-cty standard library, the same library Terraform uses, plus one of my own called random. The library is deliberately small. If you need a function that is not here, the profile is probably doing a job a shell script should do.

Expressions

An expression has access to this context:

FormMeaning
var.<name>A declared variable. See Variables.
local.<name>A resolved local. See Locals.
env.<name>The environment variable GLAZE_ENV_<name>.
path.pwd, path.baseThe current directory and its basename.
"gig-${var.district}"String interpolation.
[for e in local.editors : upper(e)]A native HCL for expression.

A ${...} wrapper is necessary only when you splice a value into a larger string. starting_directory = var.project uses the value directly.

Function library

FunctionWhat it does
chomp(string)Removes trailing newline characters.
coalesce(values...)Returns the first argument that is not null. An empty string is not null, so coalesce("", "x") returns "".
concat(lists...)Joins lists into one list.
csvdecode(string)Parses CSV text into a list of objects.
format(spec, values...)Formats a string in the style of printf.
join(separator, list)Joins the elements of a list into one string.
jsondecode(string)Parses JSON text into a value.
len(collection)Counts the elements of a collection.
lower(string)Converts a string to lower case.
random(list)Returns one random element of a list as a string. See below.
regexreplace(string, pattern, replacement)Replaces each match of a regular expression.
replace(string, search, replacement)Replaces each occurrence of a substring.
reverse(string)Reverses the characters of a string.
reverselist(list)Reverses the order of a list.
split(separator, string)Splits a string into a list.
strlen(string)Counts the characters of a string.
substr(string, offset, length)Returns a part of a string.
title(string)Converts the first letter of each word to upper case.
trim(string, characters)Removes the given characters from both ends.
trimprefix(string, prefix)Removes a prefix.
trimspace(string)Removes white space from both ends.
trimsuffix(string, suffix)Removes a suffix.
upper(string)Converts a string to upper case.

Two pairs are easy to confuse:

  • len counts the elements of a collection. strlen counts the characters of a string.
  • reverse reverses the characters of a string. reverselist reverses the order of a list, for example reverselist(local.editors).

random

random(list) returns one element of a list, chosen at random, as a string.

RuleBehaviour
ArgumentA list, a tuple or a set. A map or an object is an error.
Empty listAn error.
ElementsEach element must convert to a string.
ResultA new choice on each run.
Session nameNot allowed in the session name, directly or through a local. See Session.

The function pairs naturally with a comprehension:

HCL
locals {
  greeting = random([for g in ["hello", "hey", "yo"] : title(g)])
}

session {
  name = "daemon-run"

  window {
    name = local.greeting

    pane {
      commands = ["echo ${random(["jacked in", "online", "breach ready"])}"]
    }
  }
}

Use random() in a window name, a pane name or a command. glaze down computes the session name again, so a random session name would send down after a session that does not exist.

The full behaviour of each standard function is in the go-cty stdlib documentation. Glazier does not change the arguments or the results.