In terraform HCL, is it possible to reference an object's attribute dynamically from a variable?
I.e.:
variable "attribute" {
type = "string"
}
data "terraform_remote_state" "thing" {
not_really_important
}
output "chosen" {
value = "${data.terraform_remote_state.thing.$var.attribute}"
}
More specific to my situation, I'm looking to do this with the splat syntax:
variable "attribute" {
type = "string"
}
data "terraform_remote_state" "thing" {
count = 3 # really this is also a variable
not_really_important
}
output "chosen" {
value = "${data.terraform_remote_state.thing.*.$var.attribute}"
}
I've tried things like lookup(data.terraform_remote_state.thing, var.attribute)
and (for the splat problem) lookup(element(data.terraform_remote_state.*, count.index), var.attribute)
but they both complain about my attribute reference being incomplete/in the wrong form.