Type Constraints - Simple Types
This lesson will cover the types of variables used in Terraform.
We'll cover the following...
So far, we have been setting variables and not specified the type. This means that whatever type you pass to a variable will be the type that the variable assumes. A type constraint allows you to be specific about the type of a variable. There are three simple types:
- string
- number
- bool
Project example
To specify a type constraint, use the type property when defining a variable. Let’s see an example of using the three simple types:
Press + to interact
variable "a" {type = stringdefault = "foo"}variable "b" {type = booldefault = true}variable "c" {type = numberdefault = 123}output "a" {value = var.a}output "b" {value = var.b}output "c" {value = var.c}
In this project, we are defining three variables a
, b
, and c
. We are using the type parameter to define:
a
as a string,b
as a bool, andc
as a number.
Access this course and 1400+ top-rated courses and projects.