Created
May 1, 2018 19:02
-
-
Save justinclayton/d2935f0092618ca7d231f085e0f003a3 to your computer and use it in GitHub Desktop.
Terraform: conditionally reference a data source that may or may not exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "yes" { default = true } | |
data "template_file" "maybe" { | |
count = "${ var.yes == false ? 0 : 1 }" | |
template = "YES" | |
} | |
output "maybe" { | |
value = "${ var.yes == false ? "" : element(concat(data.template_file.maybe.*.rendered, list("")), 0) }" # <-- :_( | |
} |
it'll fail because Terraform will evaluate all variable in ternary operation before use
So if var.yes = true
then it'll generate error because data.template_file. maybe
is not defined
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks <3