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_lb_target_group_attachment does not register the EC2 instance to the target group after manually deregistered #5605

Closed
karlvlam opened this issue Aug 20, 2018 · 5 comments · Fixed by #9610
Labels
bug Addresses a defect in current functionality. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Milestone

Comments

@karlvlam
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.11.8

  • provider.aws v1.32.0
  • provider.template v1.0.0

Affected Resource(s)

  • aws_lb_target_group_attachment

Terraform Configuration Files

resource "aws_lb" "mysetup" {
  name     = "${var.aws["env"]}-mysetup-alb"
  internal           = true 
  load_balancer_type = "application"
  security_groups = ["${var.mysetup["mysetup_lb_sg"]}"]
  subnets  = "${var.subnet_pub_id}"

  enable_deletion_protection = false 

}

resource "aws_lb_target_group" "mysetup" {
  name     = "${var.aws["env"]}-mysetup-lb-tg"
  port     = 3000 
  protocol = "HTTP"
  vpc_id   = "${var.aws["vpc_id"]}"

  deregistration_delay = 20
  target_type = "instance"

  health_check = {
    interval = 7 
    protocol = "HTTP"
    path = "/"
    port = "traffic-port" 
    timeout = 5
    healthy_threshold = 5
    unhealthy_threshold = 2
    matcher = "200,201" 
  }

}


resource "aws_lb_listener" "mysetup" {
  load_balancer_arn = "${aws_lb.mysetup.arn}"
  port              = "3000"
  protocol          = "HTTP"

  default_action {
    target_group_arn = "${aws_lb_target_group.mysetup.arn}"
    type             = "forward"
  }


}

data "template_file" "mysetup_nginx" {
  template = "${file("./cloudinit/mysetup.sh")}"
  vars {
    PUB_KEY = "${file("./cloudinit/public-keys")}"
  }
}


resource "aws_lb_target_group_attachment" "mysetup_grp1" {
  count = "${aws_instance.mysetup_grp1.count}" 
  target_group_arn = "${aws_lb_target_group.mysetup.arn}"
  target_id        = "${element(aws_instance.mysetup_grp1.*.id, count.index)}"
  port             = 3000

}

resource "aws_instance" "mysetup_grp1" {
  count = "${var.mysetup["mysetup_ec2_node_grp1_count"]}"
  ami = "${var.mysetup["mysetup_ec2_ami"]}"
  instance_type        = "${var.mysetup["mysetup_ec2_type"]}"
  user_data            = "${data.template_file.mysetup_nginx.rendered}"
  key_name             = "${var.mysetup["keypair"]}"
  iam_instance_profile = "${var.mysetup["mysetup_ec2_profile"]}"

  vpc_security_group_ids = ["${var.mysetup["mysetup_ec2_sg"]}"]
  subnet_id = "${element(var.subnet_pub_id, count.index)}"
  associate_public_ip_address = true
  root_block_device {
    delete_on_termination = true
    volume_type = "gp2"
    volume_size = 8 
  }

}

Expected Behavior

terraform plan should shows there are changes of the resources

Actual Behavior

terraform plan shows there are no changes of the resources

Steps to Reproduce

  1. terraform apply
  2. terraform plan shows no changes of the resources
  3. remove an EC2 instances from the target group
  4. terraform plan still shows no changes of the resources
@bflad bflad added bug Addresses a defect in current functionality. service/elbv2 Issues and PRs that pertain to the elbv2 service. labels Sep 6, 2018
@jwadolowski
Copy link

jwadolowski commented Jun 7, 2019

Experienced the same issue this morning.

$ terraform -v
Terraform v0.11.13
+ provider.aws v1.26.0
+ provider.null v1.0.0
+ provider.template v1.0.0

aws_alb_target_group_attachment.vertx-https-1 and aws_alb_target_group_attachment.vertx-http-1 have been removed from corresponding target groups by hand for the sake of debugging. terraform apply didn't reconnect them back.

$ terraform apply
data.terraform_remote_state.ci: Refreshing state...
data.terraform_remote_state.commons: Refreshing state...
...
aws_alb_target_group_attachment.vertx-http-0: Refreshing state... (ID: arn:aws:elasticloadbalancing:eu-west-2:...xyz-20190516134148151000000005)
aws_alb_target_group_attachment.vertx-https-0: Refreshing state... (ID: arn:aws:elasticloadbalancing:eu-west-2:...xyz-20190516134147904300000002)
aws_alb_target_group_attachment.vertx-https-1: Refreshing state... (ID: arn:aws:elasticloadbalancing:eu-west-2:...xyz-20190516134147939900000004)
aws_alb_target_group_attachment.vertx-http-1: Refreshing state... (ID: arn:aws:elasticloadbalancing:eu-west-2:...xyz-20190516134148219200000006)
...

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:
...

@dbachelder
Copy link

Is there a known reliable workaround for this? This is having a major impact on our ability to move forward with some new infrastructure plans.

@bflad
Copy link
Contributor

bflad commented Aug 12, 2019

The fix for this has been merged and will release with version 2.24.0 of the Terraform AWS Provider, later this week. Thanks to @Jamian for the implementation. 👍

@ghost
Copy link

ghost commented Aug 15, 2019

This has been released in version 2.24.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Nov 1, 2019

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants