Terraform objects contain different datatypes such as variables.
There are two types of Datatypes
- Scalar variable types
- Collection variable types
Scalar Primitive Variable types
- string: It stores a group of characters enclosed in double-quotes.
variable "key_name" {
type = string
default = "aws_key"
}
- number: It is used to store the numerical values. It can be an integer or a floating number.
variable "number" {
type = number
default = 10
}
- bool:
It can be true and false values.
variable "enable_feature" {
type = bool
default = true
}
Collection variable types
The following represents complex types that hold multiple values of different types
list
: It is used to represent a group of values to pass terraform
variable "listvariable" {
type = list
default = ["one", "two", "three"]
}
set
: It is used to store values in unordered elements.
variable "setvariable" {
type = set(string)
default = ["one", "two"]
}
map
: map used to store keys and values.
variable "maptype" {
type = map(string)
default = {
key = "default-value"
}
}