|
@@ -5,11 +5,11 @@ resource "null_resource" "remote-config" {
|
|
|
provisioner "remote-exec" {
|
|
|
connection {
|
|
|
user = "ubuntu"
|
|
|
- host = "${element(aws_instance.re.*.public_ip, count.index)}"
|
|
|
+ host = "${element(aws_eip.re-eip.*.public_ip, count.index)}"
|
|
|
private_key = "${file("~/.ssh/${var.vpc-name}.pem")}"
|
|
|
agent = true
|
|
|
}
|
|
|
- inline = ["sudo apt update && sudo apt install -y python python-pip"]
|
|
|
+ inline = ["sudo apt update > /dev/null && sudo apt install -y python python-pip > /dev/null"]
|
|
|
}
|
|
|
depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc", "null_resource.inventory-setup", "null_resource.ssh-setup"]
|
|
|
}
|
|
@@ -17,23 +17,22 @@ resource "null_resource" "remote-config" {
|
|
|
###############################################################################
|
|
|
# Template Data
|
|
|
data "template_file" "ansible_inventory" {
|
|
|
- count = var.data-node-count
|
|
|
+ count = var.data-node-count
|
|
|
template = "${file("${path.module}/inventory.tpl")}"
|
|
|
vars = {
|
|
|
- host_ip = "${element(aws_instance.re.*.public_ip, count.index)}"
|
|
|
+ host_ip = "${element(aws_eip.re-eip.*.public_ip, count.index)}"
|
|
|
vpc_name = "${var.vpc-name}"
|
|
|
ncount = "${count.index}"
|
|
|
}
|
|
|
+ depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc"]
|
|
|
}
|
|
|
|
|
|
data "template_file" "ssh_config" {
|
|
|
- count = var.data-node-count
|
|
|
template = "${file("${path.module}/ssh.tpl")}"
|
|
|
vars = {
|
|
|
- host_ip = "${element(aws_instance.re.*.public_ip, count.index)}"
|
|
|
vpc_name = "${var.vpc-name}"
|
|
|
- ncount = "${count.index}"
|
|
|
}
|
|
|
+ depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc"]
|
|
|
}
|
|
|
|
|
|
###############################################################################
|
|
@@ -47,9 +46,8 @@ resource "null_resource" "inventory-setup" {
|
|
|
}
|
|
|
|
|
|
resource "null_resource" "ssh-setup" {
|
|
|
- count = var.data-node-count
|
|
|
provisioner "local-exec" {
|
|
|
- command = "echo \"${element(data.template_file.ssh_config.*.rendered, count.index)}\" > /tmp/${var.vpc-name}_node_${count.index}.cfg"
|
|
|
+ command = "echo \"${data.template_file.ssh_config.rendered}\" > /tmp/${var.vpc-name}_node.cfg"
|
|
|
}
|
|
|
depends_on = ["data.template_file.ssh_config"]
|
|
|
}
|