help with pre allocated EIP association

342 views
Skip to first unread message

McJay

unread,
Apr 7, 2017, 6:26:50 PM4/7/17
to Terraform
we have a pre allocated EIP block which we would like to use inside terraform . so we have 3 EIPs allocation id into a list in terraform variable. 


resource "aws_eip_association" "eip_assoc" {

  count = "${length(var.eiprange)}"

  instance_id   = "${element(aws_instance.yyy.*.id, count.index)}"

  allocation_id = "${var.eiprange[count.index]}"

}


resource "aws_instance" "yyy" {

count = 3

}


contents of the tfvar file


aws_region = "eu-central-1"

ami_id = "ami-d06f9ert"

eiprange = [ "eipalloc-ee64" , "eipalloc-206e" , "eipalloc-b36r"]


this works fine when i do initial terraform plan and apply. later if i terminate an instance, then use terraform apply it spins up additional instance and does EIP association. but what i see is disassociation and re- association for other 2 instances as shown below.



-/+ aws_eip_association.eip_assoc.0

    allocation_id:        "eipalloc-ee64" => "eipalloc-ee64"

    instance_id:          "i-077c4d26f4c49b721" => "${element(aws_instance.yyy.*.id, count.index)}" (forces new resource)

    network_interface_id: "eni-dd27dcb2" => "<computed>"

    private_ip_address:   "10.5.0.148" => "<computed>"

    public_ip:            "52.59.71.50" => "<computed>"


+ aws_eip_association.eip_assoc.1

    allocation_id:        "eipalloc-206e"

    instance_id:          "${element(aws_instance.yyy.*.id, count.index)}"

    network_interface_id: "<computed>"

    private_ip_address:   "<computed>"

    public_ip:            "<computed>"


-/+ aws_eip_association.eip_assoc.2

    allocation_id:        "eipalloc-b36r" => "eipalloc-b36r" 

    instance_id:          "i-0a82f42e9abe9ae4f" => "${element(aws_instance.yyy.*.id, count.index)}" (forces new resource)

    network_interface_id: "eni-706bae1f" => "<computed>"

    private_ip_address:   "10.5.0.177" => "<computed>"

    public_ip:            "35.157.216.117" => "<computed>"



I have the other 2 instances already available with EIP associated. Is there any other method that i can use so that i can avoid the modification of EIP association for existing resources


Thanks



Neil Watson

unread,
Apr 8, 2017, 9:16:32 AM4/8/17
to Terraform
You can import existing resources into terraform state, the build definitions for them: https://www.terraform.io/docs/import/usage.html
Reply all
Reply to author
Forward
0 new messages