Terraform Interpolation Syntax

Conditionals

Interpolations can contain conditionals. E.g.

resource "aws_instance" "web" {
  subnet = "${var.env == "production" ? var.prod_subnet : var.dev_subnet}"
}

using ternary operation:

CONDITION ? TRUEVAL : FALSEVAL

i.e. if var.env == "production"

then subnet = var.prod_subnet

else subnet = var.dev_subnet

 

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

Leave a Reply

Your email address will not be published. Required fields are marked *