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

config: allow local value interpolations in count #15995

Merged
merged 1 commit into from
Sep 2, 2017

Conversation

apparentlymart
Copy link
Contributor

There is some additional, early validation on the count meta-argument that verifies that only suitable variable types are used, and adding local values to this whitelist was missed in the initial implementation.

This fixes #15987.

There is some additional, early validation on the "count" meta-argument
that verifies that only suitable variable types are used, and adding local
values to this whitelist was missed in the initial implementation.
@apparentlymart apparentlymart merged commit 0a342e8 into master Sep 2, 2017
@apparentlymart apparentlymart deleted the b-local-value-count branch September 2, 2017 01:00
@antgel
Copy link

antgel commented Sep 8, 2017

@apparentlymart Thanks for this fix, I ran into the problem in as well. But I'm still suffering from the problem, using 0.10.4 which was released only a couple of days ago.

locals {
  availability_zones = [
    "${var.region}a", 
    "${var.region}b"
  ]
}

resource "aws_subnet" "sandbox-public" {
  count = "${length(locals.availability_zones)}"
  vpc_id = "${aws_vpc.sandbox.id}"
  cidr_block = "10.1.0.0/16"
  availability_zone = "${local.availability_zones[count.index]}"
  map_public_ip_on_launch = true

  tags {
    Name = "sandbox-public"
  }
}

Results in:

antony@tuxrocks:~/src/git/terraform$ terraform plan
Failed to load root config module: Error loading /home/antony/src/git/terraform/graduway.tf: locals.availability_zones: resource variables must be three parts: TYPE.NAME.ATTR in:

${length(locals.availability_zones)}

Did I miss something or is the bug still around?

@apparentlymart
Copy link
Contributor Author

Hi @antgel,

I think the problem there is that you've written locals rather than local in that interpolation; Terraform thinks you're asking for a resource of type "locals" since that's the default behavior for prefixes that aren't recognized.

I think if you change it to local then it will work:

  count = "${length(local.availability_zones)}"

@antgel
Copy link

antgel commented Sep 10, 2017

Oops, thanks for the pointer. :)

@ghost
Copy link

ghost commented Apr 7, 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 Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't use locals in resource count
3 participants