Use of Input Variables

Learn how to define and use input variables.

How to define input variables

Variables are defined in a Terraform configuration. We can supply values for those variables at runtime or set a default value for the variable to use. Terraform requires that we supply a default value for a variable at runtime if we haven’t already done so… Failing to supply a value will cause the relevant command to error out.

At its most basic, a variable can be defined with a name label and without any arguments:

Press + to interact
variable "aws_region" {}

Let’s define some more information about our aws_region:

Press + to interact
variable "aws_region" {
type = string
default = "us-east-1"
description = "The AWS region to use for this configuration"
}

We defined what data type to expect (string) and what value to default to, and we gave a ...