Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic IP for autoscaling group terraform

What's the best approach for use a same ip on autoscaling group without use a load balancer? I need to use a route53 subdomain to route to instance on autoscaling group.

For now i try to associate a elastic ip to network interface

I have this:

resource "aws_eip" "one_vault" {
  vpc                       = true
  network_interface         = "${aws_network_interface.same.id}"
  associate_with_private_ip = "10.0.1.232"
}

resource "aws_network_interface" "same_ip" {
  subnet_id   = "subnet-567uhbnmkiu"
  private_ips = ["10.0.1.16"]
}

resource "aws_launch_configuration" "launch_config" {
  image_id = "${var.ami}"
  key_name = "${var.keyname}"


}

like image 730
Brygom Avatar asked Jan 30 '26 22:01

Brygom


1 Answers

You have to do it in your user data. https://forums.aws.amazon.com/thread.jspa?threadID=52601

#!/bin/bash
 
# configure AWS
aws configure set aws_access_key_id {MY_ACCESS_KEY}
aws configure set aws_secret_access_key {MY_SECRET_KEY}
aws configure set region {MY_REGION}
 
# associate Elastic IP
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
ALLOCATION_ID={MY_EIP_ALLOC_ID}
aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $ALLOCATION_ID --allow-reassociation
like image 146
gary69 Avatar answered Feb 01 '26 20:02

gary69



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!