Variable
The variable
resource allows you to create modular and reusable configuration. Variables are defined using variable resouce
, and can provide default values which can be overriden by passing in variables to the sandbox.
The following eample defines two variables version which has a value 1.6.1
, and subnet which has a value of 10.6.0.0/16
. To use these variables inside the configuration you use the variable.<variable_name>
syntax. When using a variable on its own it is not required to encapsulate this in a string, as can be seen in the subnet example subnet = variable.subnet
, however; should you need to concatonate this variable with another then you need to encapsulate the variable.<variable_name>
inside the parentheses ${}
, for instance in a container image stanza, name = "consul:${variable.version}"
.
In addition to specifying simple string variables, it is also possible to define variables which are maps, or arrays. The following example shows the use of both of these types. In addition to the example shown below, a map can also contain an array and an array a map allowing you to mix complex types together.
Last updated