hashicorp / terraform-aws-consul

A Terraform Module for how to run Consul on AWS using Terraform and Packer
Apache License 2.0
401 stars 488 forks source link

Module consul-cluster : aws_autoscaling_attachment broken #183

Open LeComptoirDesPharmacies opened 4 years ago

LeComptoirDesPharmacies commented 4 years ago

Hi,

Since terraform AWS provider 2.21.0, it seems that we can no more use safely aws_autoscaling_attachment as described in your consul-cluster README. (See issue : https://github.com/terraform-providers/terraform-provider-aws/issues/9513)

Indeed, if we use aws_autoscaling_attachment to attach target groups to ASG created by consul-cluster, next apply on consul cluster remove the target groups of load balancer.

Documentation (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_attachment) recommends that you put ignore_changes on aws_autoscaling_group ressources :

to prevent unintended resource updates, the aws_autoscaling_group resource must be configured to ignore changes to the load_balancers and target_group_arns arguments within a lifecycle configuration block.

Do you agree with this ? Do you have any workaround ?

Thanks in advance for your answer. Yours faithfully, LCDP

brikis98 commented 4 years ago

Are you seeing an issue if you use both target_groups param on aws_autoscaling_group and the aws_autoscaling_attachment resource? Or you get an issue if you use just one of them? Could you share the code and issue you're seeing?

LeComptoirDesPharmacies commented 4 years ago

Hi @brikis98,

In fact consul_cluster do not use target_groups field so it is always omitted in module. (https://github.com/hashicorp/terraform-aws-consul/blob/ddaed275e5a2a8aa3e6388cd8c7c562f59b8feed/modules/consul-cluster/main.tf#L14)

I just use the aws_autoscaling_attachment as the documentation describe. (https://github.com/hashicorp/terraform-aws-consul/blob/master/modules/consul-cluster/README.md#how-do-you-connect-load-balancers-to-the-auto-scaling-group-asg)

Here is a "simple" reproducer : https://gist.github.com/LeComptoirDesPharmacies/3022db2067c3a98ba7d64fab1d17ab5b

If you apply once : ASG > Load Balancing menu will show the LB target groups. If you apply twice : ASG > Load balancing menu show nothing If you apply thrice : ASG > Load Balancing menu will show the LB target groups. etc...

Then, you can check the fix by replacing the module source to : github.com/LeComptoirDesPharmacies/terraform-aws-consul//modules/consul-cluster?ref=bugfix%2Fconsul-cluster-asg-attachment

Yours faithfully, LCDP

brikis98 commented 4 years ago

Understood, thanks!