0

I have successfully provision the AWS infrastructure using terraform.

While attaching more than one instance (multiple instances) to AWS ELB, I am able to attach the instances using Autoscaling.

resource "aws_elb" "abc-ext-elb" { name = "${var.galaxy}-abc-ext-elb" listener { } listener { } listener { } } security_groups = ["${aws_security_group.xxxx}"] subnets = ["${xxxxx}"] instances = ["${aws_instance.myinstance.id}"]

And also I have tried like:

"instances = "${element(aws_instance.mqttcluster.id, count.index)}" 

In both the cases it did not work

But while adding the instances without auto scaling, only one instance I am able to add using terraform, I am not able to add more than one instance from same group of instances. How to solve this issue? I did not find any module for this.

1
  • 1
    Please show your code Oct 21, 2017 at 18:44

2 Answers 2

1

How did you define your elb? it should be something like this:

resource "aws_elb" "my-elb" {
    ...
    instances = ["${aws_instance.myinstances.*.id}"]
    ...
}
6
  • resource "aws_elb" "abc-ext-elb" { name = "${var.galaxy}-abc-ext-elb" listener { } listener { } listener { } } security_groups = ["${aws_security_group.xxxx}"] subnets = ["${xxxxx}"] instances = ["${aws_instance.myinstance.id}"]
    – Raju
    Oct 22, 2017 at 10:25
  • resource "aws_elb" "abc-ext-elb" { name = "${var.galaxy}-abc-ext-elb" listener { } listener { } listener { } } security_groups = ["${aws_security_group.xxxx}"] subnets = ["${xxxxx}"] instances = ["${aws_instance.myinstance.id}"]
    – Raju
    Oct 22, 2017 at 10:25
  • And also I have tried like "instances = "${element(aws_instance.mqttcluster.id, count.index)}" like also . In both the cases it did not work.
    – Raju
    Oct 22, 2017 at 10:27
  • If you have many instances of a resource this should work aws_instance.myinstances.*.id. Check out the answer Oct 22, 2017 at 15:04
  • Thanks for response Julio. I will try now and let you know
    – Raju
    Oct 23, 2017 at 1:54
1

just remove [] from instances and it should

instances = ["${aws_instance.myinstances.*.id}"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.