Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure associating EIP: InvalidParameterCombination: You must specify an allocation id when mapping an address to a VPC instance

Given this:

resource "aws_instance" "example" {
  ami           = "ami-2757f631"
  instance_type = "t2.micro"
}

resource "aws_eip" "ip" {
  instance = "${aws_instance.example.id}"
}

from https://www.terraform.io/intro/getting-started/dependencies.html

I get an error:

* aws_eip.ip: Failure associating EIP: InvalidParameterCombination: You must specify an allocation id when mapping an address to a VPC instance

Any idea why?

like image 406
Snowcrash Avatar asked Jan 05 '23 00:01

Snowcrash


1 Answers

The aws_eip resource in Terraform uses the value of the vpc configuration attribute (true or false) as a toggle to decide if the resources ID should be it's allocation_id, or it's public_ip. We then use that ID in the API call to associate the EIP with the Instance.

In EC2 Classic, the AssociateAddress call expects the public_id value. In a EC2-VPC, it expects the allocation_id value.

For aws_eip resources attaching to Instance resources in a VPC, you need to include vpc = true in the aws_eip configuration.

like image 134
catsby Avatar answered May 05 '23 04:05

catsby