resource "aws_instance" "cluster" {
count = 3
}
resource "null_resource" "cluster" {
triggers = {
cluster_instance_ids = "${join(",", aws_instance.cluster.*.id)}"
}
connection {
host = "${element(aws_instance.cluster.*.public_ip, 0)}"
}
provisioner "local-exec" {
command = "bootstrap-cluster.sh ${join(" ", aws_instance.cluster.*.private_ip)}"
}
}
data "null_data_source" "values" {
inputs = {
all_server_ids = "${concat(aws_instance.green.*.id, aws_instance.blue.*.id)}"
all_server_ips = "${concat(aws_instance.green.*.private_ip, aws_instance.blue.*.private_ip)}"
}
has_computed_default = "default"
}
resource "aws_elb" "main" {
instances = "${data.null_data_source.values.outputs["all_server_ids"]}"
}
output "all_server_ids" {
value = "${data.null_data_source.values.outputs["all_server_ids"]}"
}
output "all_server_ips" {
value = "${data.null_data_source.values.outputs["all_server_ips"]}"
}