Terraform: No attribute `address` for `google_compute_address`

Created on 30 Sep 2015  ยท  12Comments  ยท  Source: hashicorp/terraform

I'm running into a strange error with google_compute_address when trying to export an attribute:

My config looks something like:

resource "google_compute_address" "client-address" {
  name = "nomad-address-${var.zone}-${var.count}"
  count         = "${var.count}"
}

resource "google_compute_instance" "client" {
  name          = "nomad-client-${count.index}"
  count         = "${var.count}"
  zone          = "${var.zone}"
  disk {
    image       = "${var.image}"
    size        = "${var.size}"
  }
  network_interface {
    network     = "nomad"
    access_config = {
      nat_ip = "${google_compute_address.client-address.address}"
    }
  }
  machine_type  = "n1-standard-2"
  tags          = ["nomad"]

However when, I put it into terraform, I get multiple:

* Resource 'google_compute_address.server-address' does not have attribute 'address' for variable 'google_compute_address.server-address.address'

It seems like I'm not able to reference the exportable attribute for this resource.

bug core providegoogle-cloud

Most helpful comment

Oh I see what the problem is -

instead of

nat_ip = "${google_compute_address.client-address.address}"

you need

nat_ip = "${element(google_compute_address.client-address.*.address, count.index)}"

Also - you can remove ${count.index} from the resource names, you can access elements by index using resource_name.resource_id.N.attribute where N is the index you need.

All 12 comments

Any ideas on this? Makes it hard to get a Nomad cluster up and running.

Can I use the depreciated network attribute?

Which version of Terraform are you running? It works for me on 0.6.4-dev

I don't think that's how you use count. You want to make each instance depend on the corresponding address. I'm not sure how to do it though.

Oh I see what the problem is -

instead of

nat_ip = "${google_compute_address.client-address.address}"

you need

nat_ip = "${element(google_compute_address.client-address.*.address, count.index)}"

Also - you can remove ${count.index} from the resource names, you can access elements by index using resource_name.resource_id.N.attribute where N is the index you need.

@lwander The element listing seems to work, but in order to have each iteration of the compute object be attached to the corresponding address object, they need to be iterated through upon creation at the same index.

@sparkprime 's point is well taken. I can't seem to find a way of creating a one-to-one mapping of address to compute, but still being able to access the whole list to input into a join command.

Any ideas?

I can't seem to find a way of creating a one-to-one mapping of address to compute,

The element call is giving you the 1-1 correspondence. It's mapping the compute instance with count.index = i to the ith address element in the list that's expanded.

but still being able to access the whole list to input into a join command.

You can input the whole list of address objects' address elements into a join command like this
join(",", google_compute_address.client-address.*.address)

The example "Using Templates with Count" here maps aws_instances to template_files in a 1-1 fashion.

@timfallmk did you get it working?

Shouldn't this be closed? Looks like the solution was posted.

I was hoping to hear from @timfallmk if it was working before closing this, but I guess it's been long enough.

@lwander Apologies, I don't recall what testing revealed. It should be fine to close and someone can reopen if it comes back up.

No worries at all, sounds good to me too.

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