Terraform depends on attribute accept values defined from case statements

terraform

It is clear enough based on Terraform documentation that you can have case statements for an attribute value. For example:

count = "${var.example == true ? 1 : 0}"

My question is, for the depends_on parameter can you apply the same logic?

For example:

depends_on = [$var.example == true ?resource.name : another.resource.name}

Best Answer

Interpolation isn't supported inside depends_on at this time. For example if you tried to do this:

depends_on = ["${var.test}"]

You get an error:

depends on value cannot contain interpolations: ${var.test}

The conditional you are using is a form of interpolation, therefore it's also invalid in this case.

Related Topic