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

hcl2 length() of map issue #10024

Closed
traceypooh opened this issue Feb 12, 2021 · 5 comments · Fixed by #10037
Closed

hcl2 length() of map issue #10024

traceypooh opened this issue Feb 12, 2021 · 5 comments · Fixed by #10037
Assignees
Labels
theme/docs Documentation issues and enhancements theme/hcl

Comments

@traceypooh
Copy link

For reporting security vulnerabilities please refer to the website.

If you have a question, prepend your issue with [question] or preferably use the nomad mailing list.

If filing a bug please include the following:

Nomad version

Nomad v1.0.3

Operating system and Environment details

Mac mini

Issue

job.hcl:34,15-22: Error in function call; Call to function “length” failed: collection must be a list, a map or a tuple.

Reproduction steps

locals {
  nports = "${length({ "a" = "b"})}"
}

(see also https://discuss.hashicorp.com/t/hcl2-length-of-map-issue/20911/2 )

Job file (if appropriate)

Nomad Client logs (if appropriate)

If possible please post relevant logs in the issue.

Logs and other artifacts may also be sent to: nomad-oss-debug@hashicorp.com

Please link to your Github issue in the email and reference it in the subject
line:

To: nomad-oss-debug@hashicorp.com

Subject: GH-1234: Errors garbage collecting allocs

Emails sent to that address are readable by all HashiCorp employees but are not publicly visible.

Nomad Server logs (if appropriate)

@jrasell
Copy link
Member

jrasell commented Feb 15, 2021

Hi @traceypooh and thanks for raising this issue. I can reproduce this locally but have not been able to figure the cause a the moment, so will label accordingly.

@tgross tgross added this to Needs Triage in Nomad - Community Issues Triage via automation Feb 16, 2021
@tgross tgross self-assigned this Feb 16, 2021
@tgross tgross moved this from Needs Triage to Triaging in Nomad - Community Issues Triage Feb 16, 2021
@tgross
Copy link
Member

tgross commented Feb 16, 2021

At first I suspected this was a quoting issue, but it looks like it fails with the same error even without quoting:

# map fails
locals {
  nports = length({ "a" = "b" })
}
# lists work fine
locals {
  nports = length(["a", "b"])
}

Suspecting that we actually have an "object" here and not a map, I tried using convert:

locals {
  nports = length(convert({"a" = "b"}, map(string)))
}

And that passes validation. One of the libraries we use is a little picky about object vs map but it looks like the documentation could use some improvement as well. I'll open a PR shortly with some doc fixes.

@tgross tgross added theme/docs Documentation issues and enhancements theme/hcl and removed stage/needs-investigation type/bug labels Feb 16, 2021
@tgross tgross moved this from Triaging to In Progress in Nomad - Community Issues Triage Feb 16, 2021
@traceypooh
Copy link
Author

traceypooh commented Feb 16, 2021

thanks y'all!
For now I've worked around with something like length(keys({ "a" = "b"}))

@traceypooh
Copy link
Author

whoa, @jrasell -- your name kept running through my head and just finally realized where from. levant!! 😍

Nomad - Community Issues Triage automation moved this from In Progress to Done Feb 17, 2021
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
theme/docs Documentation issues and enhancements theme/hcl
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants