Referencing Variables
Nomatron is in early access. Some advanced workflows may not be covered in the public docs.
Nomatron discovers variable references by looking for HCL identifiers that begin with NOMATRON_VAR_.
That means template variables are not magic comments or YAML placeholders. They are explicit tokens inside the HCL file.
Supported Reference Forms
Nomatron supports three practical ways to reference the same token:
- bare token
- interpolation syntax
- quoted interpolation
Examples:
count = NOMATRON_VAR_APP_JOB_COUNT
image = "${NOMATRON_VAR_APP_IMAGE_REPOSITORY}:${NOMATRON_VAR_IMAGE_TAG}"
meta {
owner = "${NOMATRON_VAR_ORG_OWNER}"
}Nomatron replaces the token with a correctly typed HCL value during rendering.
Implicit And Explicit Scope
You can write either:
- an implicit reference; or
- an explicit scoped reference.
Implicit example:
NOMATRON_VAR_IMAGE_TAGExplicit examples:
NOMATRON_VAR_GLOBAL_REGION
NOMATRON_VAR_ORG_OWNER
NOMATRON_VAR_APP_IMAGE_REPOSITORY
NOMATRON_VAR_APP_JOB_COUNTAuto-Scope Resolution
When you use the implicit form, Nomatron resolves the variable in this order:
- app job
- app
- organization
- global
That makes the implicit form useful when you want the nearest matching variable to win.
When To Use Explicit Scope
Use explicit scope when:
- the value must come from a particular layer;
- you want the template to be unambiguous for future readers; or
- a key may exist in more than one scope and you do not want auto-resolution to decide.
For example:
job "api" {
region = NOMATRON_VAR_GLOBAL_REGION
group "web" {
count = NOMATRON_VAR_APP_JOB_COUNT
task "app" {
env {
TEAM = NOMATRON_VAR_ORG_OWNER
}
}
}
}Type-Aware Substitution
Nomatron renders values according to the variable type:
stringvalues render as strings;numbervalues render as numeric literals;boolvalues render astrueorfalse; andjsonvalues render as structured JSON/HCL-compatible content.
That is why this works:
resources {
cpu = NOMATRON_VAR_APP_JOB_CPU
memory = NOMATRON_VAR_APP_JOB_MEMORY
}and this also works:
env {
IMAGE_TAG = NOMATRON_VAR_IMAGE_TAG
}Missing References
If Nomatron finds a token in the template but cannot resolve a value for it, rendering fails and the missing references are reported.
That is usually caused by one of these issues:
- the variable key does not exist in Nomatron;
- the key exists, but not in a scope available to the render;
- the environment override is missing and there is no default; or
- the template key spelling does not exactly match the variable key.
Authoring Advice
A few habits make template files easier to maintain:
- keep variable keys uppercase and consistent;
- use explicit scope when the source of truth matters;
- use implicit scope only when scope precedence is intentional;
- avoid inventing multiple keys for the same meaning; and
- keep the template readable as HCL first, not as a collection of tokens.