Member-only story

Terraform Basics — Local Variables

DevOps in HashiCorp Terrafrom series

Tony
3 min readMay 8, 2023

Note, full mind map is available at: “DevOps in Terraform MindMap

What is Local Variables in Terraform?

Local variables in Terraform are used to define reusable expressions within a module, making it easier to simplify complex configurations and improve readability.

They are only accessible within the module where they are defined and cannot be accessed by other modules. You can think of local variables as a way to create aliases or perform calculations that can be reused throughout the module.

Local values are like temporary local variables in functions. They allow you to assign a name to an expression and use that variable multiple times within a module without repeating it. You can declare a set of related local values together in a single locals block.

How to Define Local Variables?

To define a local variable, use the locals block in your Terraform configuration file (.tf file). The basic syntax for defining a local variable is:

--

--

Tony
Tony

No responses yet