» Arithmetic and Logical Operators
An operator is a type of expression that transforms or combines one or more other expressions. Operators either combine two values in some way to produce a third result value, or transform a single given value to produce a single result.
Operators that work on two values place an operator symbol between the two
values, similar to mathematical notation:
1 + 2. Operators that work on
only one value place an operator symbol before that value, like
When multiple operators are used together in an expression, they are evaluated in the following order of operations:
Parentheses can be used to override the default order of operations. Without
parentheses, higher levels are evaluated first, so
1 + 2 * 3 is interpreted
1 + (2 * 3) and not as
(1 + 2) * 3.
The different operators can be gathered into a few different groups with similar behavior, as described below. Each group of operators expects its given values to be of a particular type. Terraform will attempt to convert values to the required type automatically, or will produce an error message if this automatic conversion is not possible.
» Arithmetic Operators
The arithmetic operators all expect number values and produce number values as results:
a + breturns the result of adding
a - breturns the result of subtracting
a * breturns the result of multiplying
a / breturns the result of dividing
a % breturns the remainder of dividing
b. This operator is generally useful only when used with whole numbers.
-areturns the result of multiplying
» Equality Operators
The equality operators both take two values of any type and produce boolean values as results.
a == breturns
bboth have the same type and the same value, or
a != bis the opposite of
a == b.
» Comparison Operators
The comparison operators all expect number values and produce boolean values as results.
a < breturns
ais less than
a <= breturns
ais less than or equal to
a > breturns
ais greater than
a >= breturns
ais greater than or equal to
» Logical Operators
The logical operators all expect bool values and produce bool values as results.