Last active
April 5, 2024 19:38
-
-
Save hectorcanto/71f732dc02541e265888e924047d47ed 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
you can use
local_file
with the list with more host vars