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

TF not handling aws_autoscaling_group load_balancers correctly #15032

Closed
ghost opened this issue Sep 4, 2020 · 7 comments
Closed

TF not handling aws_autoscaling_group load_balancers correctly #15032

ghost opened this issue Sep 4, 2020 · 7 comments
Assignees
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com.

Comments

@ghost
Copy link

ghost commented Sep 4, 2020

This issue was originally opened by @darose as hashicorp/terraform#26125. It was migrated here as a result of the provider split. The original body of the issue is below.


TF is not handling aws_autoscaling_group load_balancers correctly. When I do a TF plan/apply, it does not recognize that the load balancers are attached to the ASG, and tries to delete them:

  ~ resource "aws_autoscaling_group" "master-us-east-1a-masters-use1-prod-k8s-local" {
...
      ~ load_balancers            = [
          - "api-use1-prod-k8s-local-dmvie0",
          - "api-use1-prod-k8s-local-internal",
        ]

If I allow it to do so, and then run TF plan/apply again, it then tries to perform the attachment again:

  # aws_autoscaling_attachment.master-us-east-1a-masters-use1-prod-k8s-local will be created
  + resource "aws_autoscaling_attachment" "master-us-east-1a-masters-use1-prod-k8s-local" {
      + autoscaling_group_name = "master-us-east-1a.masters.use1.prod.k8s.local"
      + elb                    = "api-use1-prod-k8s-local-dmvie0"
      + id                     = (known after apply)
    }

  # aws_autoscaling_attachment.master-us-east-1a-masters-use1-prod-k8s-local-internal will be created
  + resource "aws_autoscaling_attachment" "master-us-east-1a-masters-use1-prod-k8s-local-internal" {
      + autoscaling_group_name = "master-us-east-1a.masters.use1.prod.k8s.local"
      + elb                    = "api-use1-prod-k8s-local-internal"
      + id                     = (known after apply)
    }

Terraform Version

0.13.2

Terraform Configuration Files

Debug Output

Crash Output

Expected Behavior

Terraform should recognize that the load balancer attachments are valid and not try to remove them.

Actual Behavior

Terraform does not recognize that the load balancer attachments are valid, and so keeps alternating between adding and removing the attachments.

Steps to Reproduce

  1. terraform apply - tries to remove the ASG/load balancer attachment.
  2. terraform apply - tries to re-create the ASG/load balancer attachment.

Additional Context

References

@ghost ghost added the service/autoscaling Issues and PRs that pertain to the autoscaling service. label Sep 4, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Sep 4, 2020
@gdavison gdavison self-assigned this Sep 25, 2020
@gdavison gdavison added waiting-response Maintainers are waiting on response from community or contributor. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 25, 2020
@gdavison
Copy link
Contributor

Hi @darose, can give us some more information so that we can look into this?

  1. What version of the AWS Provider are you using? Running terraform version will include the provider version

  2. Can you show us the Terraform configuration that you're using?

@EladDolev
Copy link

same thing happens to us.
these are the configurations Kops is generating.
it also happens for target_group_arns

Terraform v0.13.3

  • provider registry.terraform.io/hashicorp/aws v3.7.0
resource "aws_autoscaling_group" "default-a-k8s-eu-west-1" {
  enabled_metrics      = ["GroupDesiredCapacity", "GroupInServiceInstances", "GroupMaxSize", "GroupMinSize", "GroupPendingInstances", "GroupStandbyInstances", "GroupTerminatingInstances", "GroupTotalInstances"]
  launch_configuration = aws_launch_configuration.default-a-k8s-eu-west-1.id
  max_size             = 3
  metrics_granularity  = "1Minute"
  min_size             = 1
  name                 = "default-a.k8s.eu-west-1"
  vpc_zone_identifier = [aws_subnet.private-a-k8s-eu-west-1.id]
}

resource "aws_autoscaling_attachment" "exttg-NLB--029644a29e076535-default-a" {
  alb_target_group_arn   = "arn:aws:elasticloadbalancing:eu-west-1:072412346744:targetgroup/NLB/029644a29e076535"
  autoscaling_group_name = aws_autoscaling_group.default-a-k8s-eu-west-1.id
}

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 29, 2020
@gdavison
Copy link
Contributor

gdavison commented Oct 2, 2020

Hi @EladDolev, does the configuration above show the complete aws_autoscaling_group, or are you specifying both target_group_arns in the aws_autoscaling_group and using aws_autoscaling_attachment resources? If you're using both, you'll have to add ignore_changes for load_balancers and target_group_arns on the aws_autoscaling_group resource.

This is documented for the aws_autoscaling_attachment resource, but not aws_autoscaling_group. I'll update the documentation to make it more clear.

If you're not using both target_group_arns and aws_autoscaling_attachment, please provide more of your configuration so that we can analyze the issue.

@gdavison gdavison added the waiting-response Maintainers are waiting on response from community or contributor. label Oct 2, 2020
@darose
Copy link

darose commented Oct 2, 2020

I wonder if the issue here is occurring as a result of using a separate "aws_autoscaling_attachment" section, rather than a "load_balancers = [...]" clause in the "aws_autoscaling_group" section?

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 2, 2020
@EladDolev
Copy link

Hi @gdavison
This is the complete configuration, with only tag blocks removed, there is no target_group_arns specified.
Same goes for what @darose reported, there is no load_balancers specified, only aws_autoscaling_attachment

These are default configurations generated by Kops, but there's nothing special about them.
IMHO it should get easily reproduced.

@gdavison gdavison added question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. and removed service/autoscaling Issues and PRs that pertain to the autoscaling service. labels Oct 6, 2020
@gdavison
Copy link
Contributor

gdavison commented Oct 6, 2020

Hi @darose and @EladDolev, I've managed to track this down. This is due to a change made in version 3.0 of the provider, and described at https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-3-upgrade#drift-detection-enabled-for-load_balancers-and-target_group_arns-arguments. It should be better documented on the resource page itself, and I'll take care of that.

This will have to be addressed in Kops, and it looks like there are several issues open for it, including #9913 and #9891.

For more reference, the issue #3265 describes the problem if target_group_arns and load_balancers are not tracked.

@ghost
Copy link
Author

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

@ghost ghost locked as resolved and limited conversation to collaborators Nov 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com.
Projects
None yet
Development

No branches or pull requests

3 participants