Want to launch ec2 instance with static public ip using terraform script

amazon-web-servicesterraform

I have one staging instance in aws whoose IP is 18.221.1.23. It is an elastic IP. Now I am writing terraform script to automate deployment using packer. Is there any way to assign this same IP while creating instance? As application has been configured in this ip.

Best Answer

The eip_association module can be utilized for that.

Use it like this:

resource "aws_eip_association" "eip_assoc" {
  instance_id   = "${aws_instance.web.id}"
  allocation_id = "EIP ID"
}

resource "aws_instance" "web" {
  ami               = "ami-21f78e11"
  availability_zone = "us-west-2a"
  instance_type     = "t1.micro"
}

Replace EIP ID with the actual Network interface id from the AWS web console.

Related Topic