Detach instance(s) from ALB Target Group

453 views
Skip to first unread message

Adam Daughterson

unread,
Mar 5, 2018, 5:40:31 PM3/5/18
to Terraform
Hello,

I'm working on providing the capability to attach and detach EC2 from an ALB Target Group.
I've found the documentation for aws_lb_target_group_attachment, but can find nothing for detachment.
Is this even possible with Terraform? Is the expectation that I should create a brand new load-balancer/target-group/listeners/etc each time I perform terraform apply?

Any help is greatly appreciated,

Adam D


Clint Shryock

unread,
Mar 7, 2018, 12:04:07 PM3/7/18
to terrafo...@googlegroups.com
Hey Adam –

You can create a LB Target group, and an EC2 Instance, and then attach them with aws_lb_target_group_attachment as you mention. Put those three in a configuration file then `terraform plan` and `terraform apply`. 

For detach, remove aws_lb_target_group_attachment from the configuration (or perhaps change which instance is in the attachment). Run `terraform plan` to verify the plan to detach that instance, then `terraform apply` to complete it. 

Please let me know if thats not what you're looking for. 

Cheers,
Clint

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/b4be444a-c86a-42be-b17b-86fc97ae5c0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Adams

unread,
Mar 7, 2018, 12:06:51 PM3/7/18
to terrafo...@googlegroups.com
You could also do this with a variable (or something calculated from a variable or resource attribute or module output) which triggers `count=0` on the aws_lb_target_group_attachment resource. Then an apply would destroy the attachment without necessarily needing to edit the TF code.

Reply all
Reply to author
Forward
0 new messages