Variable Types
Simple types: number, string, bool, null.
Complex types: Collection types: list, map, set Structural types:
object({<KEY> = <TYPE>, ...}),tuple([<TYPE>, ...])
Order of Precedence: defaults < env vars < terraform.tfvars file < terraform.tfvars.json file < .auto.tfvars < command line (-var & -var-file)
variable "environment" {
description = "Deployment environment"
type = string
default = "development"
}
# type string
variable "aws_region" {
description = "AWS Region"
type = string
default = "us-east-1"
}
# type list(string)
variable "azs" {
description = "AZs in the Region"
type = list(string)
default = ["us-east-1a", "us-east-1b", "us-east-1c"]
}
# type map
variable "amis" {
type = map(string)
default = {
"eu-west-1" = "ami-0fdke15151513145",
"us-east-1" = "ami-0d17359173587519"
}
}
# type object
variable "egress_dsg" {
type = object({
from_port = number
to_port = number
protocol = string
cidr_blocks = list(string)
})
default = {
from_port = 0,
to_port = 65365,
protocol = "tcp",
cidr_blocks = ["100.0.0.0/16", "200.0.0.0/16", "0.0.0.0/0"]
}
}