2 min read
Starting terraform 0.15 variables can be marked as sensitive, so it won't appear in plain text as a terraform output unless we explicitly request them. But we can also make the variable as non sensitive using the nonsensitive() function
07/10/2021
Read more...2 min read
Sometimes if you have some externally managed data it can come handy to be able to import it into terraform as a CSV file instead of having to manually enter all the date. To do so we can use the csvdecode() function
10/08/2021
Read more...2 min read
It's common practice to use a map in terraform to configure resources. If we want to use a map with optional values we can make use of the try() function
Let's us the following map as an example:
config = {
namespaces = ["namespace1", "namespace2"]
(...)
}
02/07/2021
Read more...2 min read
Let's imagine we have the following data structure:
locals {
queries = [
{
query = "SELECT version()"
engine = "postgresql"
},
{
query = "SELECT * FROM v$version"
engine = "oracle"
},
(...)
]
}
If we want to use just some of the items on a resource we can use for_each through the resulting array of filtering the objects using a for:
for_each = [ for item in local.queries: item if item.engine == "postgresql" ]
22/06/2021
Read more...4 min read
Let's imagine we want to create a security group with the following ingress rules:
ingress_rules = [
{
protocol = "tcp"
cidr_blocks = [ "1.1.1.1/32", "2.2.2.2/32" ]
},
{
protocol = "tcp"
cidr_blocks = [ "1.2.3.4/32" ]
}
]
For each of the following ports:
services = ["80", "443", "8080"]
We can use the terraform function setproduct() to calculate all the combinations of elements from the given sets. That's also called the Cartesian product. For this example it's going to be 2x3.
16/06/2021
Read more...