This allows us to do a range of things as engineers from simply checking if something has a value to more complex logic such as if multiple things exist within a network or have permissions to another thing.
NOTE — Return TypesIt is very important to note that both sides of the ternary expression itself MUST be the same type.
We are now going to dive into an example where we will be using the conditional as a way to feature flag some Terraform resource.
These can be used absolutely anywhere within Terraform, another example might be as follows:
In this example we are going to create a virtual machine that is significantly more powerful for our production environment than any other. It is also possible to nest these expressions to allow for checking more and more conditions, ideally you wouldn't do this unless you had no other choice however.
It is obvious to see here that the more conditions we add the harder the code becomes to read and the more brittle it becomes too. But it certainly is possible.
Sign Up and get started by using Scalr today.