I am using the below code with terraform:
#-----Workernodes-----
resource "aws_instance" "nodes-opt-us1-k8s" {
instance_type = "${var.k8s-node_instance_type}"
ami = "${var.k8s-node_ami}"
count = "${var.NodeCount}"
tags {
Name = "nodes-opt-us1-k8s"
}
key_name = "${aws_key_pair.k8s-node_auth.id}"
vpc_security_group_ids = ["${aws_security_group.opt-us1-k8s_sg.id}"]
subnet_id = "${aws_subnet.opt-us1-k8s.id}"
#-----Link Terraform worker nodes to Ansible playbooks-----
provisioner "local-exec" {
command = <<EOD
cat <<EOF > aws_worker_nodes_IP
[workers]
${aws_instance.nodes-opt-us1-k8s.*.public_ip[count.index]}
EOF
EOD
}
}
My node count has two ec2 instances being created. Everything works with just one instance so the error has to be with count.index syntax or it missing somewhere, but unable to work through it.
But I get this error returned:
Error: aws_instance.nodes-opt-us1-k8s: connection info cannot contain splat variable referencing itself
I have asked Linux Academy mentors and they are unable to see the error without deeper looking into. I am fairly new with terraform and wanted to reach out here to see if this problem has been seen before...I have googled many options but see nothing of the like.