I've just been using Terraform for a few days now and looking for guidance. I have two subnets under a vpc (private, public). What I'm trying to do is assign elastic IPs to each instance that the auto scaling group creates, or remove the elastic IP when the instance is destroyed. I've tried to follow this link: Auto assign public IPs to my instance created by an austo-scaling group
So I've created an elastic load balancer listening on port 80 and assigned it to the auto scaling group and public subnet. I've gone through the AWS docs for elastic load balancing here: https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/how-elastic-load-balancing-works.html and various others AWS provides, so I could just be thinking about the problem incorrectly. I'm unsure of how to assign the public subnet's auto scaling group's EC2 instances an elastic IP, so the only thing I can think of is it automatically handled through the elastic load balancer?
The first solution I thought of (not even sure if I can do this without being an EC2 instance), and the second is from the instructions within the first link
- Assign an elastic IP to the elastic load balancer instead of the EC2 instances, then point a DNS record to that elastic IP and then let the load balancer handle the rest
- Make a DNS record to point to the DNS of the load balancer
If the second option is correct, I will try it again and my .tf
must just be incorrect. However if there are any better options, I'd like to hear any suggestions that people have used!
Any guides, docs, or guidance would be great!