Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error tracking elastic IP addresses, and their associations to instances. #2295

Closed
kevinm416 opened this issue Jun 9, 2015 · 2 comments · Fixed by #2543
Closed

Error tracking elastic IP addresses, and their associations to instances. #2295

kevinm416 opened this issue Jun 9, 2015 · 2 comments · Fixed by #2543
Assignees

Comments

@kevinm416
Copy link

Version: Terraform v0.5.3 linux x64

Initial terraform config:

provider "aws" {
    region = "us-west-2"
}
resource "aws_vpc" "migrage-storage-environment" {
    cidr_block = "10.0.28.0/22"
    enable_dns_support = true
    enable_dns_hostnames = false
    tags {
        cloud-spec-name = "migrage-storage-environment"
    }
}
resource "aws_internet_gateway" "internet-gateway-1" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    tags {
        cloud-spec-name = "internet-gateway-1"
    }
}
resource "aws_route_table" "main-route-table" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    route {
        cidr_block = "0.0.0.0/0"
        gateway_id = "${aws_internet_gateway.internet-gateway-1.id}"
    }
    tags {
        cloud-spec-name = "main-route-table"
    }
}
resource "aws_main_route_table_association" "main-route-table-association" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    route_table_id = "${aws_route_table.main-route-table.id}"
}
resource "aws_subnet" "subnet-1" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    cidr_block = "10.0.28.0/22"
    availability_zone = "us-west-2a"
    tags {
        cloud-spec-name = "subnet-1"
    }
}
resource "aws_instance" "instance-1" {
    ami = "ami-e7527ed7"
    instance_type = "t2.micro"
    key_name = "kmorgan-aws"
    subnet_id = "${aws_subnet.subnet-1.id}"
    tags {
        Name = "instance-1"
    }
    tags {
        cloud-spec-name = "instance-1"
    }
}
resource "aws_eip" "instance-1-ip-address" {
    instance = "${aws_instance.instance-1.id}"
    vpc = true
}

This creates the instances fine:

aws_vpc.migrage-storage-environment: Creating...
  cidr_block:                "" => "10.0.28.0/22"
  default_network_acl_id:    "" => "<computed>"
  default_security_group_id: "" => "<computed>"
  dhcp_options_id:           "" => "<computed>"
  enable_dns_hostnames:      "" => "0"
  enable_dns_support:        "" => "1"
  main_route_table_id:       "" => "<computed>"
  tags.#:                    "" => "1"
  tags.cloud-spec-name:      "" => "migrage-storage-environment"
aws_vpc.migrage-storage-environment: Creation complete
aws_subnet.subnet-1: Creating...
  availability_zone:       "" => "us-west-2a"
  cidr_block:              "" => "10.0.28.0/22"
  map_public_ip_on_launch: "" => "0"
  tags.#:                  "" => "1"
  tags.cloud-spec-name:    "" => "subnet-1"
  vpc_id:                  "" => "vpc-7bed671e"
aws_internet_gateway.internet-gateway-1: Creating...
  tags.#:               "0" => "1"
  tags.cloud-spec-name: "" => "internet-gateway-1"
  vpc_id:               "" => "vpc-7bed671e"
aws_subnet.subnet-1: Creation complete
aws_instance.instance-1: Creating...
  ami:                      "" => "ami-e7527ed7"
  availability_zone:        "" => "<computed>"
  ebs_block_device.#:       "" => "<computed>"
  ephemeral_block_device.#: "" => "<computed>"
  instance_type:            "" => "t2.micro"
  key_name:                 "" => "kmorgan-aws"
  placement_group:          "" => "<computed>"
  private_dns:              "" => "<computed>"
  private_ip:               "" => "<computed>"
  public_dns:               "" => "<computed>"
  public_ip:                "" => "<computed>"
  root_block_device.#:      "" => "<computed>"
  security_groups.#:        "" => "<computed>"
  subnet_id:                "" => "subnet-cd1e73a8"
  tags.#:                   "" => "2"
  tags.Name:                "" => "instance-1"
  tags.cloud-spec-name:     "" => "instance-1"
  tenancy:                  "" => "<computed>"
  vpc_security_group_ids.#: "" => "<computed>"
aws_internet_gateway.internet-gateway-1: Creation complete
aws_route_table.main-route-table: Creating...
  route.#:                                    "" => "1"
  route.1567862030.cidr_block:                "" => "0.0.0.0/0"
  route.1567862030.gateway_id:                "" => "igw-f8a50d9d"
  route.1567862030.instance_id:               "" => ""
  route.1567862030.network_interface_id:      "" => ""
  route.1567862030.vpc_peering_connection_id: "" => ""
  tags.#:                                     "" => "1"
  tags.cloud-spec-name:                       "" => "main-route-table"
  vpc_id:                                     "" => "vpc-7bed671e"
aws_route_table.main-route-table: Creation complete
aws_main_route_table_association.main-route-table-association: Creating...
  original_route_table_id: "" => "<computed>"
  route_table_id:          "" => "rtb-831688e6"
  vpc_id:                  "" => "vpc-7bed671e"
aws_main_route_table_association.main-route-table-association: Creation complete
aws_instance.instance-1: Creation complete
aws_eip.instance-1-ip-address: Creating...
  allocation_id:     "" => "<computed>"
  association_id:    "" => "<computed>"
  domain:            "" => "<computed>"
  instance:          "" => "i-afe99058"
  network_interface: "" => "<computed>"
  private_ip:        "" => "<computed>"
  public_ip:         "" => "<computed>"
  vpc:               "" => "1"
aws_eip.instance-1-ip-address: Creation complete

Apply complete! Resources: 7 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path: terraform.tfstate

Now we delete an instance, and create a new one, and associate the new instance with a new eip address:

provider "aws" {
    region = "us-west-2"
}
resource "aws_vpc" "migrage-storage-environment" {
    cidr_block = "10.0.28.0/22"
    enable_dns_support = true
    enable_dns_hostnames = false
    tags {
        cloud-spec-name = "migrage-storage-environment"
    }
}
resource "aws_internet_gateway" "internet-gateway-1" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    tags {
        cloud-spec-name = "internet-gateway-1"
    }
}
resource "aws_route_table" "main-route-table" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    route {
        cidr_block = "0.0.0.0/0"
        gateway_id = "${aws_internet_gateway.internet-gateway-1.id}"
    }

    tags {
        cloud-spec-name = "main-route-table"
    }
}
resource "aws_main_route_table_association" "main-route-table-association" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    route_table_id = "${aws_route_table.main-route-table.id}"
}
resource "aws_subnet" "subnet-1" {
    vpc_id = "${aws_vpc.migrage-storage-environment.id}"
    cidr_block = "10.0.28.0/22"
    availability_zone = "us-west-2a"
    tags {
        cloud-spec-name = "subnet-1"
    }
}
resource "aws_instance" "instance-2" {
    ami = "ami-e7527ed7"
    instance_type = "t2.micro"
    key_name = "kmorgan-aws"
    subnet_id = "${aws_subnet.subnet-1.id}"
    tags {
        Name = "instance-2"
    }
    tags {
        cloud-spec-name = "instance-2"
    }
}
resource "aws_eip" "instance-2-ip-address" {
    instance = "${aws_instance.instance-2.id}"
    vpc = true
}

This produces an error, and does not clean up the EIP address for instance-1:

aws_vpc.migrage-storage-environment: Refreshing state... (ID: vpc-7bed671e)
aws_subnet.subnet-1: Refreshing state... (ID: subnet-cd1e73a8)
aws_internet_gateway.internet-gateway-1: Refreshing state... (ID: igw-f8a50d9d)
aws_instance.instance-1: Refreshing state... (ID: i-afe99058)
aws_route_table.main-route-table: Refreshing state... (ID: rtb-831688e6)
aws_main_route_table_association.main-route-table-association: Refreshing state... (ID: rtbassoc-34573c51)
aws_eip.instance-1-ip-address: Refreshing state... (ID: eipalloc-ce3098ab)
aws_instance.instance-1: Destroying...
aws_instance.instance-2: Creating...
  ami:                      "" => "ami-e7527ed7"
  availability_zone:        "" => "<computed>"
  ebs_block_device.#:       "" => "<computed>"
  ephemeral_block_device.#: "" => "<computed>"
  instance_type:            "" => "t2.micro"
  key_name:                 "" => "kmorgan-aws"
  placement_group:          "" => "<computed>"
  private_dns:              "" => "<computed>"
  private_ip:               "" => "<computed>"
  public_dns:               "" => "<computed>"
  public_ip:                "" => "<computed>"
  root_block_device.#:      "" => "<computed>"
  security_groups.#:        "" => "<computed>"
  subnet_id:                "" => "subnet-cd1e73a8"
  tags.#:                   "" => "2"
  tags.Name:                "" => "instance-2"
  tags.cloud-spec-name:     "" => "instance-2"
  tenancy:                  "" => "<computed>"
  vpc_security_group_ids.#: "" => "<computed>"
aws_eip.instance-1-ip-address: Destroying...
aws_instance.instance-2: Creation complete
aws_eip.instance-2-ip-address: Creating...
  allocation_id:     "" => "<computed>"
  association_id:    "" => "<computed>"
  domain:            "" => "<computed>"
  instance:          "" => "i-22e891d5"
  network_interface: "" => "<computed>"
  private_ip:        "" => "<computed>"
  public_ip:         "" => "<computed>"
  vpc:               "" => "1"
aws_eip.instance-2-ip-address: Creation complete
Error applying plan:

1 error(s) occurred:

* InvalidAssociationID.NotFound: The association ID 'eipassoc-230fdc47' does not exist
    status code: 400, request id: []

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
@kevinm416
Copy link
Author

My guess is the instance is deleted first, at which time aws takes the liberty of deleting the association between the instance and the ip address, but Terraform is not handling that properly.

@ghost
Copy link

ghost commented May 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants