Variable Types

Terraform has two main types of variables,

  • Simple types

  • Complex types

It is not required to specify the type of the variables, but it is good to mention that.

Simple type variables,

Strings,

variable "a-string" {
    type = string
}

Number,

variable "a-number" {
    type = number
}

Boolean,

variable "a-bool" {
    type = bool
}

Complex type variables,

List(type),

variable "a-list" {
  type    = list(any)
  default = [1, 2, 3]
}

A list will keep it's elements in order (ascending).

Set(type),

variable "a-set" {
  type    = set(any)
  default = [1, 2, 3]
}

A set will not keep it's elements in order we put them in, rather it will sort them and remove all duplicates.

Map(type),

variable "a-map" {
  type = map(string)
  default = {
    mykey = "my value"
  }
}

Object({ = , ...}),

Tuple([, ...]),

Last updated