Terraform: AWS EIP does not have attribute ID

Created on 18 Feb 2016  ยท  19Comments  ยท  Source: hashicorp/terraform

Hi,
When trying to associate an EIP with a AWS NAT gateway, I am seeing the following error.

02:02:03 Error applying plan:
02:02:03 
02:02:03 1 error(s) occurred:
02:02:03 
02:02:03 * Resource 'aws_eip.nat' does not have attribute 'id' for variable 'aws_eip.nat.id'

This error occurs randomly and works normally 75% of the time, the logs show that the EIP was created before the NAT gateway.

bug provideaws

Most helpful comment

Still an issue in Terraform v0.7.5

All 19 comments

Same problem here. As an added complexity, I'm using the count attribute on my aws_eip:

resource "aws_eip" "nat" {
    count = "${var.num_nat_gateways}"
    vpc = true
    depends_on = ["aws_internet_gateway.main"]
}

resource "aws_nat_gateway" "nat" {
    count = "${var.num_nat_gateways}"
    allocation_id = "${element(aws_eip.nat.*.id, count.index)}"
    subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
    depends_on = ["aws_internet_gateway.main"]
}

The error I get intermittently is:

Resource 'aws_eip.nat' does not have attribute 'id' for variable 'aws_eip.nat.*.id'

May be related to #4944. I'm trying the depends_on workaround now too.

Even using depends_on, I have experienced sometimes AWS just taking more time than usual to replicate changes made by Terraform, causing this sort of errors to show up once in a while. Waiting for a little while and re-running terraform apply has worked for me.

Got the same issue, while using different state-files
terraform apply -state=dev.tfstate ---> Runs fine and succeeds
terraform apply -state=qa.tfstate ----> Throws the following error

Error applying plan:

1 error(s) occurred:

* Resource 'aws_eip.mgmt_nat_gw' does not have attribute 'id' for variable 'aws_eip.mgmt_nat_gw.id'

Re-running the command worked though

+1

Update: the depends_on workaround in #4944 does not work.

Meet the same issue very often last days (especially when terraforming by CircleCI build process)

similar error is in #6991 with detailed logs

I'm seeing this too, when running terraform plan where the resources don't already exist. Adding a depends_on doesn't seem to help.

Running TF_VAR_availability_zones=us-east-1b,us-east-1e terraform plan on the below, when none of the resources exist on AWS, gives aws_nat_gateway.gateway #0: "allocation_id": required field is not set

variable aws_region {
  default = "us-east-1"
}

provider "aws" {
  region = "${var.aws_region}"
}

variable "availability_zones" {
  description = "Comma separated list of availability zones"
}

variable "cidrs" {
  default = {
    us-east-1b = "10.0.4.0/24"
    us-east-1d = "10.0.5.0/24"
    us-east-1e = "10.0.6.0/24"
  }
}

resource "aws_vpc" "vpc" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "public" {
  count = "${length(split(\",\", var.availability_zones))}"
  vpc_id = "${aws_vpc.vpc.id}"
  cidr_block = "${lookup(var.cidrs, element(split(\",\",var.availability_zones), count.index))}"
  availability_zone = "${element(split(\",\",var.availability_zones), count.index)}"
}

resource "aws_nat_gateway" "gateway" {
  count = "${length(split(\",\", var.availability_zones))}"
  subnet_id = "${element(aws_subnet.public.id, count.index)}"
}

It looks like using subnet_id = "${element(aws_subnet.public.*.id, count.index)}" fixes the issue.

Any news on getting this patched and fixed?

Still an issue in Terraform v0.7.5

I am also experiencing this issue on v0.7.9.

I'm seeing something similar here when I try and use the (Allocation) ID of the EIP resource. I have the following:

resource "aws_eip" "haproxy" {
  vpc = true
}

The Allocation ID is needed by keepalived configuration so that whichever host in the cluster is the master can associate the EIP to itself (disassociating it first from a considered-dead peer if necessary) so I'm trying to pass the ID in a template_file resource:

data "template_file" "haproxy" {
  count = "${var.count}"
  template = "${file("template.tpl")}"
  vars {
    ...
    allocation_id = "${aws_eip.haproxy.id}"
    ...
  }
}

When I try and apply this I get the following error:

aws_eip.haproxy: Creating...
  allocation_id:     "" => "<computed>"
  association_id:    "" => "<computed>"
  domain:            "" => "<computed>"
  instance:          "" => "<computed>"
  network_interface: "" => "<computed>"
  private_ip:        "" => "<computed>"
  public_ip:         "" => "<computed>"
  vpc:               "" => "true"
...

* Resource 'aws_eip.haproxy' does not have attribute 'id' for variable 'aws_eip.haproxy.id'

Terraform has created the EIP resource but it didn't make it into the state file so if I re-apply I end up with multiple "orphaned" EIP resources in AWS. If I remove the dependency from the data template then everything works but I don't have the ID in the templates. If I use something else like the public_ip attribute then this works fine, it seems to be just the id attribute that breaks this.

I'm seeing this with 0.8.1.

Hey folks,

Since it seems to be an intermittent issue: Is anyone still having the issue?
Would like to close it in the AWS provider if it does not exist anymore! Thanks :)

@Ninir, nop, I would close it and open a new one if it comes up again.

Thanks for letting me know @c4milo, cheers!

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gwagner picture gwagner  ยท  81Comments

phinze picture phinze  ยท  86Comments

felnne picture felnne  ยท  133Comments

jszwedko picture jszwedko  ยท  77Comments

mirogta picture mirogta  ยท  74Comments