• Loading a CSV file into terraform

    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...
  • Using terraform try function to retrieve optional values on maps

    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...
  • terraform: Using for_each over tuples

    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...
  • terraform setproduct: combine list of objects to generate all the possible combinations

    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...
  • Hide sensitive information from terraform output

    2 min read

    There are certain terraform outputs that can contain sensitive data, for example: Rendered helm values can contain sensitive data that we need to give to helm to be able to install the pods on our kubernetes cluster. Starting terraform 0.15 we can tell terraform which input and output variables are sensitives so it can hide them away from it's output.

    For example, to set an output variable as sensitive we just need to add the sensitive attribute and set it to true:

    output "helm_pet2cattle_values" {
      value     = module.pet2cattle.values
      sensitive = true
    }
    

    09/06/2021

    Read more...

Older content...

From pet to cattle
Treat your kubernetes clusters like cattle, not pets