Things I had to learn the hard way, should have called it "Terror Form"
Generating Ansible Inventory
This is the easiest way I've found; There are dynamic ansible inventories, but the code is vast and often unmaintained. I'm keeping it simple.
Start off with a file called templates/ansible/inventory.tmpl Tweak this to your own requirements.
[consul_server]
%{ for server in consul_servers ~}
${server.public} ipv4_address_private=${server.private}
%{ endfor ~}
[nomad_server]
%{ for server in nomad_servers ~}
${server.public} ipv4_address_private=${server.private}
%{ endfor ~}
[consul_client]
%{ for server in nomad_servers ~}
${server.public} ipv4_address_private=${server.private}
%{ endfor ~}
%{ for id, server in nomad_clients ~}
${server.public} ipv4_address_private=${server.private}
%{ endfor ~}
[nomad_client]
%{ for server in nomad_clients ~}
${server.public} ipv4_address_private=${server.private} %{ if server.floating != "" }ipv4_address_floating=${server.floating}%{ endif }s
%{ endfor ~}
Then in your Terraform module, you can use the following to generate the template file to a local variable.