Profiles
Variables
Declared variables, the built-in namespaces, value precedence and type validation.
Variables are what turn a .glaze file from a snapshot of one project into a template for all of them. They work the Terraform way: declare the input, give it a type, read it through var.. If you have written a variable block before, nothing here will surprise you. If you have not, the good news is that the whole feature fits on one page.
Declared variables
variable "district" {
description = "the district the gig is themed after"
type = string
default = "watson"
}
variable "fixer" {
type = string
}
session {
name = "gig-${var.district}"
window {
name = "${var.fixer}-ops"
pane {
commands = ["echo ${var.fixer} has the next job"]
}
}
}$ glaze up --var fixer=wakako # district gets its default value
$ glaze up --var district=arasaka --var fixer=wakako
A variable block has one label, the name. You read the value as var.<name> and only through that namespace.
| Argument | Required | Notes |
|---|---|---|
type | no | A bare keyword: string, number or bool. The default is string. Glazier converts the supplied value to this type. A value that cannot convert causes an error. |
default | no | A literal value of the declared type. A variable without a default is required. |
description | no | A literal string. It is documentation only. |
Rules:
- A variable without a default is required. An unset required variable is an error, and Glazier does not build a partial session.
- A
--varflag or a var file entry with a name that no block declares is an error. - Two
variableblocks with the same name are an error. glaze format --validateenforces the same contract. A required variable needs a value from--var,--var-fileor a default.
Supplying values
| Source | Form |
|---|---|
--var name=value | One value. The flag is repeatable. A --var without = is a usage error, exit code 2. |
--var-file <path> | A native HCL file of name = value attributes. Glazier does not support JSON var files. |
district = "watson"
fixer = "wakako"$ glaze up --var-file watson.hcl --var fixer=rogue # fixer from the flag, district from the file
Glazier applies values in this order: the default first, then the var file, then each --var flag. The last value for a name wins.
| Precedence | Source |
|---|---|
| 1, lowest | The default in the variable block |
| 2 | The --var-file |
| 3, highest | Each --var flag, in command order |
Type conversion
Glazier converts each supplied value and each default to the declared type before it starts a session. A --var value is text, so the conversion matters.
| Type | Accepted values |
|---|---|
string | Any text. |
number | A number, for example 1 or 2.5. The text two is an error. |
bool | true, 1, false or 0 only. TRUE, yes and every other value are errors. |
variable "base_index" {
type = number
default = 1
}
variable "verbose" {
type = bool
default = false
}
session {
name = "typed-demo"
options = {
"base-index" = "${var.base_index}"
}
window {
pane {
commands = ["server --verbose=${var.verbose}"]
}
}
}--var base_index=two is rejected before the session starts. The message says that “two” is not a number. --var verbose=true lands as --verbose=true. --var verbose=TRUE does not:
$ glaze format --validate --stdout --profile-path typed.glaze --var verbose=TRUE
Error: Invalid variable value
on typed.glaze line 6, in variable "verbose":
6: variable "verbose" {
The value supplied for variable "verbose" is not a valid bool: a bool is
required; to convert from string, use lowercase "true".
the glaze profile contains errors
Built-in namespaces
These namespaces sit alongside var. and need no declaration.
| Namespace | Value |
|---|---|
env.<name> | The environment variable GLAZE_ENV_<name>, without the prefix. GLAZE_ENV_token=abc123 becomes env.token. |
path.pwd | The current working directory. |
path.base | The basename of the current working directory. |
local.<name> | A value from a locals block. See Locals. |
session {
name = "gig-${var.district}"
starting_directory = path.pwd
window {
name = upper(path.base)
pane {
commands = ["deploy --token ${env.token}"]
}
}
}$ GLAZE_ENV_token=abc123 glaze up --var district=watson
Only variables with the GLAZE_ENV_ prefix reach the profile. The rest of your environment does not, so a profile cannot read $HOME or $AWS_SECRET_ACCESS_KEY unless you pass it on purpose.
A deleted working directory
On Linux, a deleted working directory makes the current directory unreadable. Glazier then leaves out the path namespace. A profile that uses path.pwd or path.base fails with “Current directory not available” and points at the first use. A profile that does not use them still works. A session without starting_directory also needs the current directory, so set the attribute in that case.
down evaluates only the name
glaze down evaluates only the session name. A variable that appears only deeper in the profile is not required for teardown. When the name needs a variable that has no value, down reports “Required variable not set” for that variable and no other. Thus teardown stays idempotent for scripts. See down.
Why the prefix on env?
Because a profile is a file you commit, and the whole environment of your shell is not something a committed file should be able to read by accident. The GLAZE_ENV_ prefix makes every exposure a decision you took at the command line. It is a little more typing. It is also the reason a profile from a stranger cannot interpolate your cloud credentials into a window name.
The longer worked example, one profile that serves many projects, is on its own page: One profile, many projects.