Brygom
Brygom

Reputation: 848

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}"


}

Upvotes: 3

Views: 1832

Answers (2)

gary69
gary69

Reputation: 4230

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

Upvotes: 2

Shakti Garg
Shakti Garg

Reputation: 377

Terraform doesn't support this functionality as auto-scaling groups are managed by cloud provider like AWS, not by it. For more details: https://github.com/hashicorp/terraform/issues/7060

Upvotes: 0

Related Questions