Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_elb TF resource tries to remove ASG attached EC2 instances #2508

Closed
CpuID opened this issue Jun 26, 2015 · 6 comments
Closed

aws_elb TF resource tries to remove ASG attached EC2 instances #2508

CpuID opened this issue Jun 26, 2015 · 6 comments

Comments

@CpuID
Copy link
Contributor

CpuID commented Jun 26, 2015

Currently using the following logic in my .tf file (a few names changed to generic names below):

resource "aws_autoscaling_group" "asg_name" {
  availability_zones = ["us-east-1a", "us-east-1d"]
  name = "asg_name"
  max_size = 2 
  min_size = 2 
  health_check_grace_period = 300 
  health_check_type = "ELB"
  desired_capacity = 2 
  min_elb_capacity = 2 
  force_delete = false
  launch_configuration = "${aws_launch_configuration.lc_name.id}"
  load_balancers = ["${aws_elb.elb_name.name}"]
  vpc_zone_identifier = ["${var.subnet.1a}", "${var.subnet.1d}"]

  tag {
    key = "stack"
    value = "..."
    propagate_at_launch = true
  }
}

resource "aws_launch_configuration" "lc_name" {
  name = "lc_name"
  image_id = "ami_id"
  instance_type = "t2.small"
  iam_instance_profile = "profile_name"
  key_name = "..."
  security_groups = ["..."]
  associate_public_ip_address = true
  user_data = ""
}

resource "aws_elb" "elb_name" {
  name = "elb_name"
  subnets = ["${var.subnet.1a}", "${var.subnet.1d}"]
  security_groups = ["..."]

  listener {
    instance_port = 20000
    instance_protocol = "tcp"
    lb_port = 20000
    lb_protocol = "tcp"
  }

  health_check {
    healthy_threshold = 2
    unhealthy_threshold = 2
    timeout = 3
    target = "TCP:20000"
    interval = 5
  }

  # NOTE - EC2 instances are added by the ASG here as they are spawned.
  instances = []
  cross_zone_load_balancing = true
}

Seeing this when running "terraform plan", after updating the AMI ID on the Launch Configuration:

~ aws_autoscaling_group.asg_name
    launch_configuration: "lc_name" => "${aws_launch_configuration.lc_name.id}"

~ aws_elb.elb_name
    instances.#: "2" => "0"

This causes the ELB to remove active instances, as opposed to leaving them online pending termination/replacement.

@CpuID
Copy link
Contributor Author

CpuID commented Jun 26, 2015

Possibly relates to #1552 in terms of workflow.

Is this a bug? Or am I doing something wrong? Thanks :)

@CpuID CpuID changed the title aws_elb resource tries to remove ASG attached instances aws_elb TF resource tries to remove ASG attached EC2 instances Jun 26, 2015
@phinze
Copy link
Contributor

phinze commented Jun 26, 2015

Hi @CpuID - it's pretty simple actually - by explicitly specifying instances = [] you're telling terraform that you want the instance collection for the ELB to be empty. If you omit that line, everything should work as expected.

@phinze phinze closed this as completed Jun 26, 2015
@CpuID
Copy link
Contributor Author

CpuID commented Jun 26, 2015

Awesome, thanks will do :)

@gozer
Copy link

gozer commented Jul 28, 2015

Interestingly, if you mix both, you still face this bug. Like in my case, I have the same example as the OP, with the only difference that my ELB definition does include an instance, as a non-ASG derived member instance. And that's by design. I want my ELB to route traffic to that single special instance as well as to the ASG instances.

The result I am seeing is identical to the original bug report. Running successful terraform apply removes the instances associated from the ASG, leaving only my initial special instance in the ELB.

@phinze
Copy link
Contributor

phinze commented Jul 28, 2015

@gozer i'm not sure the AWS API makes it easy to model that use case - is it possible for you to refactor such that your "special instance" lives in a second ASG with a min/max/desired of 1/1/1 and that same ELB attached? then autoscaling will populate the instances into the load balancer for you.

@ghost
Copy link

ghost commented May 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants