You are currently viewing Terraform Expressions

Terraform Expressions

Terraform Expressions

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed terraform in-built functions.

In this blog post, we will discuss terraform expressions. Expressions are used to refer to or compute values within a configuration. The simplest expressions are just literal values, like “hello” or 5, but the Terraform language also allows more complex expressions such as references to data exported by resources, arithmetic, conditional evaluation, and a number of built-in functions.

Literal Expressions:

A literal expression is an expression that directly represents a particular constant value. Terraform has a literal expression syntax for each of the value types described below.

Conditional Expressions:

A conditional expression uses the value of a bool expression to select one of two values.

For Expressions:

A for expression creates a complex type value by transforming another complex type value. Each element in the input value can correspond to either one or zero values in the result, and an arbitrary expression can be used to transform each input element into an output element. For expression is a new feature and available from Terraform 0.12 onwards.

Splat Expressions:

A splat expression provides a more concise way to express a common operation that could otherwise be performed with a for expression. The special [*] symbol iterates over all of the elements of the list given to its left and accesses from each one the attribute name given on its right.

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.

Next, we are going to explain terraform expressions with examples. We will use terraform null resource for this demo.

Terraform expressions:

Hope you have enjoyed this article. In the next blog post, we will discuss terraform workspaces.

For the complete list of terraform expressions, please refer below terraform documentation

To get more details on terraform, please refer below terraform documentation.


Leave a Reply