Shared Variables

Template Shared Variables

Template shared variables are available to all template definition config blocks, template views, and params. These variables are defined in the config/variables folder. The variables files are merely ruby scripts where instance variables (variables with an @ sign in front) are made available.

Here’s an example:


@ami = "ami-base"

The @ami variable is now available to all of your templates. Effective use of shared variables can dramatically shorten down your template definitions.

Layering Support

Variables also support layering. Layering is performed for the config/variables folder. Let’s say you have the following variables directory structure:

├── base.rb
├── development.rb
└── production.rb

In this case, you want to define your common variables used for templates in the config/variables/base.rb. Specific environment overrides can be defined in their respective LONO_ENV variables file. For example:


@min_size = 1
@max_size = 1


@min_size = 10
@max_size = 20

When lono generate is called with LONO_ENV=production it will use 20 for the @max_size variable. For other LONO_ENV values, the @max_size variable will be set to 1.

Depending on how you use variables with layering, you can dramatically simpify your template definitions and param files. Most of the time, you can get the template definition to a single line and use a single config/params/base file for the template.

More details on layering is covered in Layering Support.

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub and contributions are encouraged and welcomed. We love pull requests from you!