Expressions compute values in Terraform. Beyond literals and references, a handful of expression forms let you make decisions, transform collections and generate repeated blocks without writing a general-purpose program. A conditional expression uses the form condition ? true_value : false_value. For example, instance_type = var.environment == "prod" ? "m5.large" : "t3.micro". Both results should be of the same type, or convertible to one, because Terraform must know the result type. A common idiom is count = var.create_bucket ? 1 : 0 to make a resource optional.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 5 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.