Terraform Variables
Jul 18, 2023
Variable Types
- List
variable "mylist" {
type = list
default = ["apple", "banana", "carrot"]
}
- Extracting an element from a list
var.mylist[0] # Zero is the index number
OR
element(mylist, 0)
2. Nested List
variable "mynestedlist" {
type = list
default = [
["apple", "banana", "carrot"],
["dog", "elephant", "frog"]
]
}
- Output the Flatten or merged nested list
output "flat_list" {
value = flatten(var.mynestedlist)
}
# This will result to
["apple", "banana", "carrot", "dog", "elephant", "frog"]
3. Map
variable "countries_map" {
default = {
ph = "Philippines"
sg = "Singapore"
us = "United States"
}
}
- Output and extracting Map
output "country" {
value = lookup(var.country_map, "ph")
}
4. Strings
variable "mystring" {
type = string
default = "This is a string"
}