Terraform Variables (Part-2)

Kamalesh D
7 min readAug 11, 2023

In the following article, we explore the utilization of variables within Terraform, a tool that employs HashiCorp Configuration Language (HCL) to define infrastructure setups. The approach in Terraform is declarative, where multiple code blocks are defined to establish a desired infrastructure arrangement.

Before delving into the diverse variable types, it’s constructive to conceptualize the entire Terraform configuration as a unified function. Concerning variables, they operate akin to functions, taking on roles similar to function arguments, return values, and local variables. These roles align with input variables, output variables, and local variables within the Terraform context.

The topics we’ll address encompass:

  1. Local variables
  2. Input variables
  3. Incorporating environment variables
  4. Output variables
  5. Constraints

Types of Variables

Local Variables

  • Local variables are established within the locals block, constituting a collection of key-value associations applicable within the configuration. These values might either be explicitly defined or linked to other variables or resources.
  • Accessible solely within the module or…

--

--

Kamalesh D
Kamalesh D

Written by Kamalesh D

DevOps and Cloud Enthusiast | Cyber Security | DevSecOps Engineer@FordMotors | https://dev.to/kamaleshseervi