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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow parametrization for unregistration of all targets in target groups when attaching instance/ip to target group #11343

Open
obourdon opened this issue Dec 18, 2019 · 1 comment 路 May be fixed by #11370
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elbv2 Issues and PRs that pertain to the elbv2 service.

Comments

@obourdon
Copy link
Contributor

obourdon commented Dec 18, 2019

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 other comments that do not add relevant new information or questions, 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

Description

Having looked at the aws/resource_aws_lb_target_group_attachment.go code and considering the fact that by default, AWS/terraform-aws-provider (don't know which one) assigns all spawned instances in an Autoscaling group to all listeners in target group, it might be interesting to add an extra argument which, if specified to non-default false value, cleans up all existing attached targets prior to register the give one. Currently, without this argument the list of targets remain unchanged

New or Affected Resource(s)

  • aws_lb_target_group_attachment

Potential Terraform Configuration

resource "aws_lb_target_group_attachment" "monitoring" {
    count            = "${var.monitoring_enable * var.cluster_size}"
    target_group_arn = "${element(aws_lb_target_group.monitoring.*.arn, count.index)}"
    target_id        = "${element(data.aws_instances.asg_instances.ids, count.index)}"
    port             = 12345
    replace_all_targets = true
 }

References

None

@obourdon obourdon added the enhancement Requests to existing resources that expand the functionality or scope. label Dec 18, 2019
@ghost ghost added the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Dec 18, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 18, 2019
@obourdon obourdon linked a pull request Dec 19, 2019 that will close this issue
obourdon added a commit to obourdon/terraform-provider-aws that referenced this issue Dec 20, 2019
Cleans up all existing attached targets prior to
register the new given one
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 22, 2021
@ljluestc
Copy link

resource "aws_lb_target_group" "example" {
  name     = "example-target-group"
  port     = 80
  protocol = "HTTP"
  vpc_id   = "your-vpc-id"
}

# Deregister all existing targets
resource "aws_lb_target_group_attachment" "deregister" {
  target_group_arn = aws_lb_target_group.example.arn
  count            = length(data.aws_instances.asg_instances.ids)

  target_id = data.aws_instances.asg_instances.ids[count.index]
  port      = 80

  lifecycle {
    create_before_destroy = true
  }
}

# Register new targets
resource "aws_lb_target_group_attachment" "register" {
  target_group_arn = aws_lb_target_group.example.arn
  count            = var.monitoring_enable * var.cluster_size

  target_id = element(data.aws_instances.asg_instances.ids, count.index)
  port      = 80
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants