Is there a way AND/OR conditional operator in terraform?

user2062360 picture user2062360 · Sep 14, 2016 · Viewed 26.4k times · Source

Is there a way to use something like this in Terraform?

count = "${var.I_am_true}"&&"${var.I_am_false}"

Answer

NicoKowe picture NicoKowe · Aug 16, 2018

This is more appropriate in the actual version (0.12.X)

The supported operators are:

Equality: == and !=
Numerical comparison: >, <, >=, <=
Boolean logic: &&, ||, unary !

https://www.terraform.io/docs/configuration/interpolation.html#conditionals

condition_one and condition two:

count = var.condition_one && var.condition_two ? 1 : 0

condition_one and NOT condition_two:

count = var.condition_one && !var.condition_two ? 1 : 0

condition_one OR condition_two:

count = var.condition_one || var.condition_two ? 1 : 0