Unable to associate eip

Getting the following error

Error: Error associating EIP: MissingParameter: Either public IP or allocation id must be specified
status code: 400

Here is my configuration file:

provider “aws” {
region = “us-east-1”
access_key = “”
secret_key = “”
}

resource “aws_eip_association” “myeip” {
instance_id = “aws_instance.myweb.id”
}

resource “aws_instance” “myweb” {
ami = “ami-09d069a04349dc3cb”
instance_type = “t2.micro”
security_groups = ["${aws_security_group.mysg.name}"]

}

resource “aws_security_group” “mysg” {
name = “web-server-sg”

ingress {
from_port = 80
to_port = 80
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}

ingress {
from_port = 443
to_port = 443
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}

ingress {
from_port = 22
to_port = 22
protocol = “tcp”
cidr_blocks = [“116.75.30.5/32”]
}

ingress {
from_port = 21
to_port = 21
protocol = “tcp”
cidr_blocks = [“116.75.30.5/32”]
}

ingress {
from_port = 25
to_port = 25
protocol = “tcp”
cidr_blocks = [“116.75.30.5/32”]
}
}

In order to associate an EIP with an instance, you need to first create an aws_eip resource

I created the aws_eip resource the issue remains unchanged.

Assuming your EIP resource is called “myeip”, then the association resource should be something like this

resource "aws_eip_association" "myeip" {
  instance_id   = aws_instance.myweb.id
  allocation_id = aws_eip.myeip.id
}

Note the difference between instance_id = aws_instance.myweb.id which resolves to the id of the EC2 instance defined in the Terraform resource “aws_instance” “myweb”; and instance_id = "aws_instance.myweb.id" which resolves to the string “aws_instance.myweb.id” - and that is not an instance id.

eip

@bentterp now getting this error

What is the name of your eip resource? That’s the name you should use in the association resource.

The problem has been resolved after removing “” from the interpolation.