Skip to content

Instantly share code, notes, and snippets.

@davistran86
Forked from hectorcanto/inventory.tf
Created July 12, 2018 14:28
Show Gist options
  • Save davistran86/cbfa86da712286b379442e6435d12db3 to your computer and use it in GitHub Desktop.
Save davistran86/cbfa86da712286b379442e6435d12db3 to your computer and use it in GitHub Desktop.
Produce an Ansible inventory from a Terraform template
data "template_file" "inventory" {
template = "${file("inventory.tpl")}"
vars {
backend_ip = "${aws_instance.backend.public_ip}"
frontend_ip = "${aws_instance.frontend.public_ip}"
landing_ip = "${aws_instance.landing.public_ip}"
key_path = "${var.instance_key_path}"
}
}
resource "null_resource" "update_inventory" {
triggers {
template = "${data.template_file.inventory.rendered}"
}
provisioner "local-exec" {
command = "echo '${data.template_file.inventory.rendered}' > ../inventory"
}
}
[backend]
${backend_ip}
[frontend]
${frontend_ip}
[landing]
${landing_ip}
[all:vars]
ansible_ssh_private_key_file = ${key_path}
ansible_ssh_user = ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment