Terraform: AWS ELB Cant Get Attribute

Created on 23 Jul 2015  ·  13Comments  ·  Source: hashicorp/terraform

I have set up a route53 alias to point to an ELB, as in the example. This worked great for creating it. However, I modified some parts of the records, and now when i try terraform refresh I get:

Error configuring: 12 error(s) occurred:

* Resource 'aws_elb.external' does not have attribute 'zone_id' for variable 'aws_elb.external.zone_id'
* Resource 'aws_elb.external' does not have attribute 'dns_name' for variable 'aws_elb.external.dns_name'
* Resource 'aws_elb.external' does not have attribute 'zone_id' for variable 'aws_elb.external.zone_id'
* Resource 'aws_elb.external' does not have attribute 'dns_name' for variable 'aws_elb.external.dns_name'
* Resource 'aws_elb.external' does not have attribute 'zone_id' for variable 'aws_elb.external.zone_id'
* Resource 'aws_elb.frontend' does not have attribute 'dns_name' for variable 'aws_elb.frontend.dns_name'
* Resource 'aws_elb.frontend' does not have attribute 'zone_id' for variable 'aws_elb.frontend.zone_id'
* Resource 'aws_elb.external' does not have attribute 'dns_name' for variable 'aws_elb.external.dns_name'
* Resource 'aws_elb.external' does not have attribute 'dns_name' for variable 'aws_elb.external.dns_name'
* Resource 'aws_elb.external' does not have attribute 'zone_id' for variable 'aws_elb.external.zone_id'
* Resource 'aws_elb.external' does not have attribute 'zone_id' for variable 'aws_elb.external.zone_id'
* Resource 'aws_elb.external' does not have attribute 'dns_name' for variable 'aws_elb.external.dns_name'

I am confused what the problem is, because it was able to create the route53 records correctly, using those variables.

bug core

All 13 comments

I tried deleting the ELBs and records manually and removing them from the state, so it has to recreate them, but I am getting the same error.

OK I managed to work around this by removing all the route53 terraform defintions, creating the ELBs, then adding them back in. Then I didn't get that error.

This might have to do with the fact that I am creating the route53 items in a module, passing in the ELB info, like this:

module "first" {
  source = "./public-route"
  zone_id = "ddd"
  name = "domain.com"

  alias_name = "${aws_elb.external.dns_name}"
  alias_zone_id = "${aws_elb.external.zone_id}"
}

module "secnd" {
  source = "./public-route"
  zone_id = "ddd"
  name = "calls-api"

  alias_name = "${aws_elb.external.dns_name}"
  alias_zone_id = "${aws_elb.external.zone_id}"
}

Within the ./public-route module, are you accessing these values as (e.g.) ${var.alias_name}} rather than explicitly ${aws_elb.external.dns_name}? The resource namespace is separate for each module, so the child module only has access to the data passed in via its variables.

Yes in the module I am accessing them as vars. It does work some of the time, like I mentioned in the previous comment, so the syntax is correct, it just fails on updating.

So, you have to create your environment, then create more of your environment, there's gotta be a better way than this. I'm having the same issue.

I can confirm we're having the same issue as well. Even adding an explicit depends_on = ["resource_type.resource_name"] doesn't solve the problem. This looks like a bug, and is potentially the same issue as reported in #2859 and #2583. It appears related to modules.

I've been able to deterministically reproduce the bug as follows:

Works fine:

  • Module A

    • Invokes Module B

    • Creates Resource 1

Causes error:

  • Module A

    • Invokes Module B

    • Creates Resource 1

    • Invokes Module C



      • with Parameter whose value is a property on Resource 1



Interestingly, there's even a param passed into Module A that now fails once I invoke Module C.

I can't share my Terraform templates publicly, but if a specific person wants to see them, I'd be happy to share.

@josh-padnick I managed to create a simple reproduction of the bug.

Debug log of destroy command,

The repository contains everything needed for reproduction :
https://github.com/shanielh/terraform_module_bug/tree/master/main

This issue effects us quite a bit and slows down development with Terraform, since the workarounds require a lot of commenting and manual state management.

Would be willing to dive deeper on the issue if I could be pointed in the right direction!

It's now coming up on a year since the last comment, and I just hit this bug again (TF version 0.7.1). In my case, I am not using variables, but directly accessing aws_elb resources which are _internal to the module_. This prevents me from abstracting out repeated collections of resources into self-contained modules. Instead what I have is hundreds of lines of copy-paste and find-and-replace (from iam all the way up through route53), which I would prefer to avoid. Manual state management is a complete non-starter. Any chance that we're going to see a fix?

I ran the reproduction that @shanielh posted and I can confirm older versions failed but the latest Terraform version succeeds so this was fixed at some point.

@ajk8 Could you open a new issue with a reproduction since the above repro is now fixed?

Did this break again? Because literally using the Alias record example is failing with Terraform v0.7.10.

mhenkel@C02RP5M7G8WP مثابرة ~/pfpt/src/efp-aws-kafka-zookeeper/kafka/t
cat t.tf
resource "aws_elb" "main" {
  name = "foobar-terraform-elb"
  availability_zones = ["us-east-1c"]

  listener {
    instance_port = 80
    instance_protocol = "http"
    lb_port = 80
    lb_protocol = "http"
  }
}

resource "aws_route53_record" "www" {
  zone_id = "${aws_route53_zone.primary.zone_id}"
  name = "example.com"
  type = "A"

  alias {
    name = "${aws_elb.main.dns_name}"
    zone_id = "${aws_elb.main.zone_id}"
    evaluate_target_health = true
  }
}
mhenkel@C02RP5M7G8WP مثابرة ~/pfpt/src/efp-aws-kafka-zookeeper/kafka/t
terraform plan
module root: 1 error(s) occurred:

* resource 'aws_route53_record.www' config: unknown resource 'aws_route53_zone.primary' referenced in variable aws_route53_zone.primary.zone_id
mhenkel@C02RP5M7G8WP مثابرة ~/pfpt/src/efp-aws-kafka-zookeeper/kafka/t
terraform -v                                                                                                                                                                                             ⏎
Terraform v0.7.10

The example is just referencing something that doesn't exist for example reasons (our examples aren't fully complete cause it can require many more resources). In this case, you're referencing a non-existent zone.

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