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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With