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

Can't compare against a lookup or map interpolation #10847

Closed
onlyanegg opened this issue Dec 19, 2016 · 2 comments · Fixed by #10886
Closed

Can't compare against a lookup or map interpolation #10847

onlyanegg opened this issue Dec 19, 2016 · 2 comments · Fixed by #10886

Comments

@onlyanegg
Copy link

Terraform Version

Terraform v0.8.1

Affected Resource(s)

  • Interpolation

Terraform Configuration Files

variable "role" {
  description = "Overwrite the role variable "
  default = "plat"
}
variable "elb_role" {
  type = "map"
  description = "Role name of ELB if provisioning multiple ELBs"
  default = {
    plat = 2
  }
}

Expected Behavior

Should have printed "yes"

Actual Behavior

Got a type error

Steps to Reproduce

$ terraform console
> lookup(var.elb_count, var.role)
2
> lookup(var.elb_count, var.role) > 1 ? "yes" : "no"
At column 3, line 1: <, >, <= and >= may apply only to int and float values in:

${lookup(var.elb_count, var.role) > 1 ? "yes" : "no"}
> var.elb_count[var.role] > 1 ? "yes" : "no"
At column 3, line 1: <, >, <= and >= may apply only to int and float values in:

${var.elb_count[var.role] > 1 ? "yes" : "no"}
> (var.elb_count[var.role] + 0) > 1 ? "yes" : "no"
yes
>
@apparentlymart
Copy link
Contributor

Thanks for filing this, @onlyanegg! We discussed this a bit in Glitter chat.

The last line of the reproduction steps above is the workaround I would suggest for anyone running into this issue before it gets fixed.

I believe the issue here is that the comparison operators are not correctly promoting string operands to a numeric type as we'd do for arithmetic operators. This is the same class of problem as hashicorp/hil#43, so I may just fix them both together since it'll be touching similar areas of the code anyway.

@ghost
Copy link

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

Successfully merging a pull request may close this issue.

3 participants