Skip to content

Variables

Variables are the primary way to parameterize your templates. They are defined in boilerplate.yml and their values are provided interactively, via CLI flags, or from YAML files.

variables:
- name: ProjectName
description: The name of the project
type: string
default: "my-project"
order: 1
validations:
- required
- length-3-50
FieldRequiredDescription
nameYesThe variable name, used in templates as {{ "{{" }} .Name {{ "}}" }}
descriptionNoHuman-readable description shown during interactive prompts
typeNoOne of: string, int, float, bool, list, map, enum. Defaults to string
defaultNoDefault value if the user doesn’t provide one
optionsEnum onlyList of allowed values for enum type
orderNoInteger controlling the order variables are prompted (lower = first)
referenceNoName of another variable to reference for complex types
validationsNoList of validation rules

The default type. Accepts any text value.

- name: Name
type: string
default: "hello"

An integer value.

- name: Port
type: int
default: 8080

A floating-point number.

- name: Ratio
type: float
default: 0.75

A boolean (true or false).

- name: EnableFeature
type: bool
default: true

An ordered list of values. Provide via CLI as YAML syntax:

- name: Tags
type: list
default:
- tag1
- tag2

CLI: --var 'Tags=["web", "api"]'

A key-value map. Provide via CLI as YAML syntax:

- name: Config
type: map
default:
key1: value1
key2: value2

CLI: --var 'Config={host: "localhost", port: "8080"}'

A constrained set of choices. The options field is required.

- name: Environment
type: enum
options:
- dev
- staging
- production
default: dev

Validations run in real-time during interactive prompts, showing which rules pass or fail as the user types.

ValidationDescription
requiredValue cannot be empty
length-{min}-{max}Character count must be within range (e.g., length-3-50)
urlMust be a valid URL
emailMust be a valid email address
alphaEnglish letters only
digitDigits only
countrycode2ISO 3166 Alpha-2 country code
semverSemantic versioning format (e.g., 1.2.3)
regex(pattern)Custom regex pattern (e.g., regex(^[a-z0-9-]+$))
- name: SlugName
type: string
description: URL-friendly project slug
validations:
- required
- length-3-30
- regex(^[a-z0-9-]+$)

For complex types (list, map), you can reference another variable instead of using Go template interpolation in defaults:

variables:
- name: Services
type: list
default:
- api
- web
- name: PrimaryService
type: string
reference: Services # References the Services list

Simple variable defaults can reference other variables using Go template syntax:

variables:
- name: AppName
default: "my-app"
- name: ContainerName
default: "{{ "{{" }} .AppName {{ "}}" }}-container"

Variables can be provided in multiple ways. When the same variable is set in more than one place, the highest-precedence source wins:

  1. --var CLI flags (highest)
  2. Dependency-level var_files
  3. --var-file CLI files
  4. Dependency variable defaults
  5. Root variable defaults in boilerplate.yml
  6. Environment variables (BOILERPLATE_VAR_<NAME>)
  7. Interactive prompts (lowest)

Pass individual values directly on the command line:

Terminal window
boilerplate \
--template-url ./my-template \
--output-folder ./output \
--var ProjectName="My App" \
--var Port=8080 \
--var 'Tags=["web", "api"]'

For complex types (lists, maps), use YAML syntax wrapped in quotes.

To set a variable for a specific dependency, prefix it with the dependency name:

Terminal window
--var 'backend.Port=9090'

Load multiple variables at once from a YAML file:

Terminal window
boilerplate \
--template-url ./my-template \
--output-folder ./output \
--var-file vars/common.yml \
--var-file vars/production.yml

The YAML file is a flat key-value map:

vars/production.yml
ProjectName: "My App"
Port: 8080
Environment: production
Tags:
- web
- api
Config:
host: "prod.example.com"
port: "443"

You can pass --var-file multiple times. Later files override earlier ones, so environment-specific files can override shared defaults.

Inside boilerplate.yml, a dependency can specify its own var files:

dependencies:
- name: backend
template-url: ../go-service
output-folder: ./backend
var_files:
- ../vars/backend-defaults.yml

These take precedence over CLI-level --var-file values for that dependency.

Set variables via environment variables using the BOILERPLATE_VAR_ prefix:

Terminal window
export BOILERPLATE_VAR_ProjectName="My App"
export BOILERPLATE_VAR_Port=8080
boilerplate \
--template-url ./my-template \
--output-folder ./output \
--non-interactive

In interactive mode (the default), Boilerplate prompts for any variable that hasn’t been provided by any of the above methods. In --non-interactive mode, a missing variable with no default causes an error.