Alternatively you could put the AMIs in an array, and just iterate over that array.
locals {
nomad_ami = [
"${data.aws_ami.nomadclient_tick.image_id}",
"${data.aws_ami.nomadclient_tock.image_id}",
]
}
resource "aws_instance" "nomadclients" {
count = 6
ami = "${element(local.nomad_ami, count.index)}"
...
}
Because of these headaches, we decided to abandon hcl for these use cases and ended up writing our own preprocessor that takes a JSON configuration and generates individual JSON-based HCL (ie. .json.tf) that terraform can then use. We can leverage proper templating to generate many variants of a single resource in a higher level language, while still using terraform to manage the infrastructure and it only adds one additional step to the plan + apply process.