Locals in Detail
Explore how to define and utilize Terraform locals as reusable expressions and fixed values. Understand their syntax and usage within Terraform projects, including referencing other locals and resource outputs. This lesson helps you organize and simplify your infrastructure code by creating meaningful, composite values.
We'll cover the following...
Terraform local
A local is Terraform’s representation of a normal programming language variable. Confusingly, Terraform also has a concept called a variable which is really an input (variables are covered in the variables chapter). A local can refer to a fixed value such as a string, or it can be used to refer to an expression such as two other locals concatenated together.
Project example
Let’s dive into an example:
Project code in detail
In the code above:
-
We define a local block by using the keyword
localsand then an opening{...