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

Fail to read variables with a validation block a > symbol #126

Closed
elisiariocouto opened this issue Feb 1, 2023 · 2 comments
Closed

Fail to read variables with a validation block a > symbol #126

elisiariocouto opened this issue Feb 1, 2023 · 2 comments

Comments

@elisiariocouto
Copy link
Contributor

elisiariocouto commented Feb 1, 2023

Hello. I have a terraform file with the following content:

variable "abc" {
  type        = string
  validation {
    condition     = length(var.abc) > 2 && can(regex("^[a-z0-9]+$", var.abc))
    error_message = "My error message"
  }
}

This fails to load with hcl.load() with the following error message:

unexpected GT; expected COMMA, IDENTIFIER, STRING, COMMENT, MULTICOMMENT, MINUS, NUMBER, FLOAT, $end, RIGHTBRACE, RIGHTBRACKET, COLON, RIGHTPAREN

After some tests, ternary ifs and inequalities also fail.

resource "random_password" "password" {
   count = 1 > 2 ? 0 : 1
}

or

resource "random_password" "password" {
   count = true ? 0 : 1
}
@sahilsk
Copy link

sahilsk commented Feb 1, 2023

Works for me. Are you sure you are on updated version?

python-hcl2 4.3.0
lark        1.1.5
variable "abc" {
  type        = string
  validation {
    condition     = length(var.abc) > 2 && can(regex("^[a-z0-9]+$", var.abc))
    error_message = "My error message"
  }
}
{
  "variable": [
    {
      "abc": {
        "type": "${string}",
        "validation": [
          {
            "condition": "${length(var.abc) > 2 && can(regex(\"^[a-z0-9]+$\", var.abc))}",
            "error_message": "My error message"
          }
        ]
      }
    }
  ]
}

@elisiariocouto
Copy link
Contributor Author

I'm sorry, I confused the libraries. I was using another library to parse HCL. Well, time to move to this one :) Sorry about this. Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants