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

Issue parsing nested parenthesis in hcl files #74

Closed
cesar-rodriguez opened this issue Jun 20, 2020 · 1 comment
Closed

Issue parsing nested parenthesis in hcl files #74

cesar-rodriguez opened this issue Jun 20, 2020 · 1 comment

Comments

@cesar-rodriguez
Copy link

Description

pyhcl is not able to handle parsing of hcl files containing nested parenthesis.

How to reproduce the issue

pyhcl: v0.4.4
Python: 3.7.5

$ cat test.tf 
locals {
  map = {
    r1 = "21.0.0.0/16"
    r2 = "22.4.0.0/16"
  }

  sg = {
    "test" = [
      "r1",
      "r2"
    ]
  }

}

resource "aws_security_group" "test" {
  name   = "testshubham"
  vpc_id = "vpc-xxxxxxxxx"

  dynamic "ingress" {
    for_each = local.sg.test
    content {
      from_port   = 80
      to_port     = 80
      protocol    = "tcp"
      cidr_blocks = split(",", lookup(local.map, ingress.value, ingress.value))
    }
  }
}

$ python
Python 3.7.5 (default, Jan  1 2020, 15:46:16) 
[Clang 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hcl
>>> with open('test.tf', 'r') as fp:
...   obj = hcl.load(fp)
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/therasec/.pyenv/versions/terrascan/lib/python3.7/site-packages/hcl/api.py", line 62, in load
    return loads(fp.read(), export_comments=export_comments)
  File "/Users/therasec/.pyenv/versions/terrascan/lib/python3.7/site-packages/hcl/api.py", line 81, in loads
    return HclParser().parse(s, export_comments=export_comments)
  File "/Users/therasec/.pyenv/versions/terrascan/lib/python3.7/site-packages/hcl/parser.py", line 643, in parse
    s, lexer=Lexer(export_comments=export_comments), debug=DEBUG
  File "/Users/therasec/.pyenv/versions/terrascan/lib/python3.7/site-packages/hcl/ply/yacc.py", line 503, in parse
    tok = self.errorfunc(errtoken)
  File "/Users/therasec/.pyenv/versions/terrascan/lib/python3.7/site-packages/hcl/parser.py", line 634, in p_error
    raise ValueError(msg)
ValueError: Line 26, column 397: unexpected LEFTPAREN; expected ASTERISK_PERIOD, RIGHTBRACKET, COMMA, RIGHTPAREN, ADD, MINUS, MULTIPLY, DIVIDE
@virtuald
Copy link
Owner

That appears to be HCL2 which is not supported by pyhcl. See the readme for alternative parsers.

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