2020-10-27 02:15:36 +01:00
|
|
|
---
|
2021-11-23 00:57:25 +01:00
|
|
|
layout: "language"
|
|
|
|
page_title: "Expressions - Configuration Language"
|
|
|
|
description: "An overview of expressions to reference or compute values in Terraform configurations, including types, operators, and functions."
|
2020-10-27 02:15:36 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# Expressions
|
|
|
|
|
2020-12-01 22:12:12 +01:00
|
|
|
> **Hands-on:** Try the [Create Dynamic Expressions](https://learn.hashicorp.com/tutorials/terraform/expressions?in=terraform/configuration-language&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial on HashiCorp Learn.
|
|
|
|
|
2020-10-27 02:15:36 +01:00
|
|
|
_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.
|
|
|
|
|
|
|
|
Expressions can be used in a number of places in the Terraform language,
|
|
|
|
but some contexts limit which expression constructs are allowed,
|
|
|
|
such as requiring a literal value of a particular type or forbidding
|
2021-11-23 00:57:25 +01:00
|
|
|
[references to resource attributes](/docs/language/expressions/references.html#references-to-resource-attributes).
|
2020-11-13 03:01:48 +01:00
|
|
|
Each language feature's documentation describes any restrictions it places on
|
|
|
|
expressions.
|
2020-10-27 02:15:36 +01:00
|
|
|
|
|
|
|
You can experiment with the behavior of Terraform's expressions from
|
|
|
|
the Terraform expression console, by running
|
2021-11-23 00:57:25 +01:00
|
|
|
[the `terraform console` command](/docs/cli/commands/console.html).
|
2020-10-27 02:15:36 +01:00
|
|
|
|
|
|
|
The other pages in this section describe the features of Terraform's
|
|
|
|
expression syntax.
|
2020-11-13 03:01:48 +01:00
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Types and Values](/docs/language/expressions/types.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents the data types that Terraform expressions can resolve to, and the
|
|
|
|
literal syntaxes for values of those types.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Strings and Templates](/docs/language/expressions/strings.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents the syntaxes for string literals, including interpolation sequences
|
|
|
|
and template directives.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [References to Values](/docs/language/expressions/references.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents how to refer to named values like variables and resource attributes.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Operators](/docs/language/expressions/operators.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents the arithmetic, comparison, and logical operators.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Function Calls](/docs/language/expressions/function-calls.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents the syntax for calling Terraform's built-in functions.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Conditional Expressions](/docs/language/expressions/conditionals.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents the `<CONDITION> ? <TRUE VAL> : <FALSE VAL>` expression, which
|
|
|
|
chooses between two values based on a bool condition.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [For Expressions](/docs/language/expressions/for.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents expressions like `[for s in var.list : upper(s)]`, which can
|
|
|
|
transform a complex type value into another complex type value.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Splat Expressions](/docs/language/expressions/splat.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents expressions like `var.list[*].id`, which can extract simpler
|
|
|
|
collections from more complicated expressions.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Dynamic Blocks](/docs/language/expressions/dynamic-blocks.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents a way to create multiple repeatable nested blocks within a resource
|
|
|
|
or other construct.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Type Constraints](/docs/language/expressions/type-constraints.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents the syntax for referring to a type, rather than a value of that
|
|
|
|
type. Input variables expect this syntax in their `type` argument.
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
- [Version Constraints](/docs/language/expressions/version-constraints.html)
|
2020-11-13 03:01:48 +01:00
|
|
|
documents the syntax of special strings that define a set of allowed software
|
|
|
|
versions. Terraform uses version constraints in several places.
|