When using Terraform aws
provider, I want to attach my aws_autoscaling_group
instances to my Application Load Balancer target group (aws_lb_target_group
).
Should I only use resource aws_autoscaling_attachment
or should I use an argument target_group_arns
in the aws_autoscaling_group
resource ? What is the difference between those two ways or will the result be the same and these are just two different ways to do the same thing ?
If you look at the documentation for either one of those resources, at the very top of the documentation page is a section highlighted in yellow titled "NOTE on Auto Scaling Groups, Attachments and Traffic Source Attachments" That note specifically says that Terraform provides two ways of making that attachment, and you just need to make sure you use only one of the two methods. It doesn't matter which method you use.
Terraform provides two methods, because sometimes one of the resources could be controlled outside of Terraform, or in a different Terraform stack, so you would have to use the aws_autoscaling_attachment
resource in that scenario.