Autoscaling Group with ELB

1,686 views
Skip to first unread message

Miguel Cruz

unread,
Aug 12, 2015, 4:47:34 PM8/12/15
to Terraform
Is it possible to have terraform create a Autoscaling group and use an (internal) ELB on the same tf file?

I tried but got an error saying the ELB needs to exist prior to the Autoscaling group creation happens.

Code:
resource "aws_elb" "elasticz" {
  name = "awslbielasticz-appq01"
  subnets = ["subnet-########", "subnet-#######"]
  security_groups = ["${var.SGes}","${var.SG-app}"]
  internal = "true"
    listener {
      instance_port = 9200
      instance_protocol = "http"
      lb_port = 8080
      lb_protocol = "http"
  }
  health_check {
    healthy_threshold = 2
    unhealthy_threshold = 3
    timeout = 3
    target = "HTTP:9200/"
    interval = 30
  }
}

resource "aws_launch_configuration" "es_launch_config" {
  image_id = "ami-########"
  instance_type = "m1.medium"
  iam_instance_profile = "ReadOnly"
#Create before we teardown
  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_autoscaling_group" "pet_es" {
  name = "example-config"
  launch_configuration = "${aws_launch_configuration.es_launch_config.name}"
  availability_zones = ["us-east-1a", "us-east-1c"]
  load_balancers = ["aws_elb.elasticz.name"]
  max_size = 3
  min_size = 2
}


Error:
aws_autoscaling_group.pet_es: Error: 1 error(s) occurred:

* Error creating Autoscaling Group: ValidationError: Provided ELBs may not be valid. Please ensure they exist and try again.
        status code: 400, request id: [3efeffc9-4131-11e5-8efe-fbdf1add1d1b]
aws_elb.elastic: Creation complete
Error applying plan:

1 error(s) occurred:

* Error creating Autoscaling Group: ValidationError: Provided ELBs may not be valid. Please ensure they exist and try again.
        status code: 400, request id:


Paul Hinze

unread,
Aug 12, 2015, 4:58:31 PM8/12/15
to terrafo...@googlegroups.com
Hi Miguel,

I haven't seen this particular error before, but one thing I noticed about your config is that you're using subnet_ids on your ELB but not vpc_zone_identifiers on your ASG.

(The attribute name asymmetry here is unfortunate, but it comes from AWS. For now we're sticking to naming attributes to match upstream APIs - down the road we may introduce "attribute aliases" to help improve clarity in cases like this.)

So perhaps the ASG is getting launched into a different VPC or into EC2-Classic, so it cannot see the ELB?

Let me know if specifiying vpc_zone_identifiers on the ASG sorts things out,

Paul

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/b0dbb764-c901-49cb-94eb-a2953e18d8a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joshua Garnett

unread,
Aug 12, 2015, 5:59:50 PM8/12/15
to terrafo...@googlegroups.com
Hi Miguel,

You have a typo.  load_balancers = ["aws_elb.elasticz.name"] should be load_balancers = ["${aws_elb.elasticz.name}"] 

--Josh

Miguel Cruz

unread,
Aug 12, 2015, 7:21:16 PM8/12/15
to terrafo...@googlegroups.com

Thanks for the suggestions, I will try it out when I get back to the keyboard.

-Miguel

harr...@apphodge.com

unread,
Dec 21, 2015, 10:34:49 PM12/21/15
to Terraform
Hey Miguel,

Did you ever get to the bottom of this? I am running into a similar issue when trying to add an existing elb to an existing asg.

[WARN] Error updating Load Balancers for AutoScaling Group (apphodge-asg), error: ValidationError: Provided ELBs may not be valid. Please ensure they exist and try again.

I get a nearly identical error if I try to create them both together:

Error creating Autoscaling Group: ValidationError: Provided ELBs may not be valid. Please ensure they exist and try again.

harr...@apphodge.com

unread,
Dec 21, 2015, 10:39:08 PM12/21/15
to Terraform
I fixed the issue I was having. I was passing elb.dns_name not elb.name. I was going to add the elb manually with the UI and then try terraform refresh, but noticed that the UI prepopulates the load balancers field with the elb name NOT dns name.

shrikkannt

unread,
Jun 30, 2016, 5:25:09 AM6/30/16
to Terraform
Hai, if you have any code to spin up 2 ELB in AWS by using terraform please forward me  i am getting errors.
Regards
Srikanth
Reply all
Reply to author
Forward
0 new messages