...

/

Terraform Variables: Local and Environment

Terraform Variables: Local and Environment

Learn about Terraform's local and environment variables and how to work with them.

Overview

One of the advantages of writing our infrastructure as code is the ability to use variables to store values as we require. The ability to use just a single configuration for different target environments enhances the flexibility of IaC. The code below shows the syntax to create a variable in Terraform:

Press + to interact
variable "variable_name" {
type = string || number || bool || list || tuple || map || object
description = "Any description"
default = "The default value for the variable"
}

The major parameters include:

  • variable_name: This is the given name of the variable.
  • type: This is the type of variable we’re creating. The value can be either string, number, bool, list, tuple, map, or object.
  • description: This describes what our variable is for.
  • default: This is the default value of our variable.

The code snippet below shows a typical use case where we create variables for a VPC resource and then use these variables to create the ...