Everyone in the tech field has heard the term “Stay DRY” or some variation of it. We all understand the above, but when it comes to count conditional statements across multiple resources in Terraform, I often see one of two things happen: This is literally the thing we are trying to prevent with DRY. It is: Granted, in this context the repetition is not the end of the world, but let’s be more efficient if we can be.

Typically, when you are using count conditional statements across multiple resources in Terraform, you are trying to do one of two things: Both of these scenarios can be easily addressed in Terraform using local variables.

This is to demonstrate that additional logic can be added in the event you have optional resources.

Related Articles