aplusp
aplusp

Reputation: 715

How to format strings in Terraform conditional?

I'm trying to formulate a parameter based on the following conditions in Terraform v0.12

Paraphrasing-


if var.role != ""
    role = role/var.role      >>> assign role
else 
    role = var.role        >>> assign just empty string and not "role/"

The following does not work

role    = "${var.role != "" ? role/var.role : var.role}"

OR

role    = "${var.role != "" ? "role/" + var.role : var.role}"

OR 

role    = "${var.role != "" ? role/${var.role} : var.role}"

Any idea how to format this?

Upvotes: 11

Views: 4588

Answers (1)

aplusp
aplusp

Reputation: 715

For anyone looking, this worked-

role    = "${var.role != "" ? "role/${var.role}" : var.role}"

Upvotes: 18

Related Questions