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

Expand operator not recognizing a locals' type #23536

Closed
tul1 opened this issue Dec 2, 2019 · 5 comments
Closed

Expand operator not recognizing a locals' type #23536

tul1 opened this issue Dec 2, 2019 · 5 comments
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@tul1
Copy link

tul1 commented Dec 2, 2019

Terraform Version

v0.12.6

Terraform Configuration Files

data "cloudplatform_xxxx" "all" {}

locals {
  available_images = [for image in data.cloudplatform_xxxx.all.images: {
                        id = image.id,
                        name = image.name,
                        creation_date = "${formatdate("YYYY", image.creation_date) * 31556926 +
                                           formatdate("MM", image.creation_date) * 2629743 +
                                           formatdate("DD", image.creation_date) * 604800 +
                                           formatdate("hh", image.creation_date) * 3600 +
                                           formatdate("mm", image.creation_date) * 60 +
                                           formatdate("ss", image.creation_date)}"
                     }]

  newest_image_creation_date = max(local.available_images[*].creation_date...)
  newest_image = [for image in local.available_images: 
                    image if image.creation_date == local.newest_image_creation_date
                 ][0]
}

Debug Output

$ terraform console
> max(local.available_images[*].creation_date...)
63757516898

Actual Behavior

Error: Invalid expanding argument value

  on main.tf line 15, in locals:
  15:   newest_image_creation_date = max(local.available_images[*].creation_date...)

The expanding argument (indicated by ...) must be of a tuple, list, or set
type.

Additional Context

When I run the command with terraform console it works well but when I do terraform apply a type error is raised.

@danieldreier danieldreier added bug v0.12 Issues (primarily bugs) reported against v0.12 releases labels Dec 2, 2019
@jbardin
Copy link
Member

jbardin commented Dec 6, 2019

Thanks for filing the issue @tul1,

I was hoping it was the * evaluation here that was being processed incorrectly, but turns out that it's the first for expression that seems to be causing problems. It's possible we don't have the full type information at the point where we're evaluating the ... expansion.

I created a simpler reproduction here that exhibits the same failure, and succeeds in the console as well:

variable "input" {
  type = list(object({
    a = string
    b = number
  }))

  default = [{
    a = "a"
    b = 1
  }]
}

locals {
  objects = [for o in var.input: {
    id = o.a
    num = o.b
  }]
  max_num = max([for o in local.objects: o.num]...)
}

output "max" {
  value = local.max_num
}

@jbardin jbardin added the config label Dec 6, 2019
@jbardin jbardin removed their assignment Dec 6, 2019
@albertomardomingo
Copy link

I think I may be running into the same error here (If it's a different one, I'll be happy to fill a new issue).

Running this code:

locals {
  public_files = [
    for filename in fileset(path.module, "/zones/zonename/public/*.yaml") : 
      yamldecode(file(filename)).entries
  ]
  entries_public_yaml = merge(local.public_files...)
}
output "public_files" {
  value = local.public_files
}

works just fine, but running

variable "zone_folder" {
  default = "zones/zonename"
}
locals {
  public_files = [
    for filename in fileset(path.module, "/${var.zone_folder}/public/*.yaml") : 
      yamldecode(file(filename)).entries
  ]
  entries_public_yaml = merge(local.public_files...)
}
output "public_files" {
  value = local.public_files
}

results in the same error:

Error: Invalid expanding argument value
 
  on zonename.tf line 33, in locals:
  33:   entries_public_yaml = merge(local.public_files...)

The expanding argument (indicated by ...) must be of a tuple, list, or set
type.

As far as I can tell, the local.public_files list is exactly the same in both cases (piping the output to files and running a diff against them returns "files are identical")

To be hones, I'm not completely sure wether I'm just blind as a bat, is the same bug, or a completely unrelated one, but since I'm getting the same error, I'd imagine it would at least be somewhat related.

Sorry if this is unrelated and I have to open a new bug.

@timbrammer
Copy link

timbrammer commented Jan 15, 2020

I'd like to +1 this one. I've got a similar situation. Simpler even:

data "null_data_source" "bits" {
  count = 4
  inputs = {
    "key-${count.index}" = count.index
  }
}

output "results" {
  value = values(merge(data.null_data_source.bits.*.outputs...))
}

This gets me:

The expanding argument (indicated by ...) must be of a tuple, list, or set
type.

@hashibot
Copy link
Contributor

Hello! 🤖

This issue seems to be covering the same problem or request as #22404, so we're going to close it just to consolidate the discussion over there. Thanks!

@ghost
Copy link

ghost commented Apr 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 Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

6 participants