Terraform Conditionals

While terraform makes a lot of infrastructure deployment easy, sometimes it can feel a little bit like trying to thread a needle with while wearing oven mitts. The idea is simple, the execution is hard. One of those principles that hasn’t found it’s way into the HCL is the idea of conditionals.

Let’s say you’re trying to write a service module. The meat of this particular class of service is the same whether provided publicly or privately. So you may want to add a parameter to your module that allows the end user to choose whether to make it a public service or a private service. The public service just needing a handful of different components such as where the DNS zone is created, which TLS certificates to use, how to configure the load balancer, etc.