terraform/website/docs/configuration/expressions.html.md

158 lines
3.9 KiB
Markdown
Raw Normal View History

---
layout: "language"
page_title: "Expressions Landing Page - Configuration Language"
sidebar_current: "docs-config-expressions"
---
# Expressions Landing Page
To improve navigation, we've split the old Expressions page into several smaller
pages.
<a id="types-and-values"></a>
<a id="advanced-type-details"></a>
<a id="type-conversion"></a>
<a id="literal-expressions"></a>
<a id="indices-and-attributes"></a>
## Types and Values, Literal Expressions, Indices and Attributes
Terraform's types are `string`, `number`, `bool`, `list`, `tuple`, `map`,
`object`, and `null`.
This information has moved to
[Types and Values](/docs/language/expressions/types.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
<a id="references-to-named-values"></a>
<a id="local-named-values"></a>
<a id="named-values-and-dependencies"></a>
<a id="references-to-resource-attributes"></a>
<a id="local-named-values-1"></a>
<a id="values-not-yet-known"></a>
## References to Named Values (Resource Attributes, Variables, etc.)
You can refer to certain values by name, like `var.some_variable` or
`aws_instance.example.ami`.
This information has moved to
[References to Values](/docs/language/expressions/references.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
<a id="arithmetic-operators"></a>
<a id="equality-operators"></a>
<a id="comparison-operators"></a>
<a id="logical-operators"></a>
## Arithmetic and Logical Operators
Operators are expressions that transform other expressions, like adding two
numbers (`+`) or comparing two values to get a bool (`==`, `>=`, etc.).
This information has moved to
[Operators](/docs/language/expressions/operators.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
## Conditional Expressions
The `condition ? true_val : false_val` expression chooses between two
expressions based on a bool condition.
This information has moved to
[Conditional Expressions](/docs/language/expressions/conditionals.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
<a id="expanding-function-arguments"></a>
<a id="available-functions"></a>
## Function Calls
Terraform's functions can be called like `function_name(arg1, arg2)`.
This information has moved to
[Function Calls](/docs/language/expressions/function-calls.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
<a id="for-expressions"></a>
## `for` Expressions
Expressions like `[for s in var.list : upper(s)]` can transform a complex type
value into another complex type value.
This information has moved to
[For Expressions](/docs/language/expressions/for.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
<a id="splat-expressions"></a>
<a id="legacy-attribute-only-splat-expressions"></a>
website: Draw better attention to for and for_each patterns When helping folks in the community forum, I commonly see questions around more complex patterns in transforming deep data structures into different shapes to work with for_each. We have examples of these patterns in the docs for the functions that they rely on, but they were not previously very discoverable in the main configuration language documentation sections. Here I've moved the "Using Expressions in for_each" subsection on the Resources page above some of the other sub-sections to hopefully make it easier to see, and written out in more detail the two specific patterns that answer a significant number of for_each-related user questions in the hope that readers will be more likely to realize that the links are relevant to what their goals. I also added some more elaboration about the behavior of converting from list to set in the "Using Sets" subsection, because this feature is often a user's first encounter with the set data type and I've inferred from some of the questions I've answered that a number of Terraform users don't have prior experience with set data types in other languages to draw assumptions from. Finally, I added some similar links to the for_each patterns within the for expression documentation itself, to try to make those examples more visible to those who might be discovering the documentation in a different sequence, e.g. by following a deep link shared in an answer to a question in the community forum.
2020-06-01 20:23:56 +02:00
## Splat Expressions
Expressions like `var.list[*].id` can extract simpler collections from complex
collections.
This information has moved to
[Splat Expressions](/docs/language/expressions/splat.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
<a id="dynamic-blocks"></a>
<a id="best-practices-for-dynamic-blocks"></a>
## `dynamic` Blocks
The special `dynamic` block type serves the same purpose as a `for` expression,
except it creates multiple repeatable nested blocks instead of a complex value.
This information has moved to
[Dynamic Blocks](/docs/language/expressions/dynamic-blocks.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>
<a id="string-literals"></a>
<a id="string-templates"></a>
<a id="interpolation"></a>
<a id="directives"></a>
## String Literals and String Templates
Strings can be `"double-quoted"` or
```hcl
<<EOT
heredocs
EOT
```
Strings can also include escape sequences like `\n`, interpolation sequences
(`${ ... }`), and template sequences (`%{ ... }`).
This information has moved to
[Strings and Templates](/docs/language/expressions/strings.html).
2021-08-20 16:31:26 +02:00
<div style="height: 30vh; margin: 0; padding: 0;"></div>