-
-
Save davistran86/cbfa86da712286b379442e6435d12db3 to your computer and use it in GitHub Desktop.
Produce an Ansible inventory from a Terraform template
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
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" | |
} | |
} |
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
[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