Course outlines for learning terraform.
A bit of information on the different type of data structures in Terraform.
This is the simplest form, for example:
hello = "world"
Here the variable hello
is filled with the value world
.
By the way, in a .tf file, if you quote a value, it’s literally that value. Without quotes would be a reference. For example:
hello = resource.identifier.id
Would assign the value of resource.identifier.id
to the varialbe hello
.
Almost like a string, but not quoted and numeric:
value = 123
other_value = 123.123
You can do arithmetic operations with numbers:
value = 2
other_value = "${var.value * 3}"
May look like an unquoted string, but can only be true
or false
:
enable_feature_x = true
enable_feature_y = false
A list is a sequence of values. For example:
hello = ["one", "two", "world"]
A list typically contains “similar” items.
A map, mapping or dictionary (different words for the same concept) looks like this:
hello = {
one = "hello"
two = "world"
}
(Just like a dictionary that has some word and an explanation.)
Mappings can be used to map a value like so:
city = "paris"
_region = {
amsterdam = "eu-west-1"
paris = "eu-central-1"
oslo = "eu-north-1"
}
region = _region[city]
NOTE: The above example won’t work, as these structures should be in a variable (var.something
) or a local (local.something
). It’s just to explain then concept.
You can also have lists of maps: (or actually any kind of structure.)
list = [
{
some = "thing"
},
{
other = "things"
}
]
(A bit opinionated…)
From simple to complex:
true
or false
.