virtuald / pyhcl

HCL is a configuration language. pyhcl is a python parser for it.
Mozilla Public License 2.0
336 stars 60 forks source link

AttributeError: 'unicode' object has no attribute 'iteritems' in 0.2.0 #7

Closed kvz closed 8 years ago

kvz commented 8 years ago

Hey, thanks for hcltool!

0.2.0 solves a few issues for me, but also introduces a regression.

When I try to convert the following HCL:

resource "aws_security_group" "fw-infra-tusd-main" {
  name        = "fw-infra-tusd-main"
  description = "Infra tusd"

  # SSH
  ingress {
    from_port   = "22"
    to_port     = "22"
    protocol    = "tcp"
    cidr_blocks = [
      "${var.ip_kevin}",
      "${var.ip_marius}",
      "${var.ip_tim}"
    ]
  }

  # Web
  ingress {
    from_port   = "8080"
    to_port     = "8080"
    protocol    = "tcp"
    cidr_blocks = [
      "${var.ip_all}"
    ]
  }
}

via

hcltool infra.tf infra.json

I'm getting

Traceback (most recent call last):
  File "/usr/local/bin/hcltool", line 45, in <module>
    main()
  File "/usr/local/bin/hcltool", line 35, in main
    obj = hcl.load(infile)
  File "/Library/Python/2.7/site-packages/hcl/api.py", line 51, in load
    return loads(fp.read())
  File "/Library/Python/2.7/site-packages/hcl/api.py", line 62, in loads
    return HclParser().parse(s)
  File "/Library/Python/2.7/site-packages/hcl/parser.py", line 287, in parse
    return self.yacc.parse(s, lexer=Lexer())
  File "/Library/Python/2.7/site-packages/ply/yacc.py", line 265, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/Library/Python/2.7/site-packages/ply/yacc.py", line 971, in parseopt_notrack
    p.callable(pslice)
  File "/Library/Python/2.7/site-packages/hcl/parser.py", line 103, in p_object_0
    p[0] = self.objectlist_flat(p[2])
  File "/Library/Python/2.7/site-packages/hcl/parser.py", line 70, in objectlist_flat
    for k2, v2 in iteritems(vv):
  File "/Library/Python/2.7/site-packages/hcl/parser.py", line 27, in iteritems
    return iter(d.iteritems())
AttributeError: 'unicode' object has no attribute 'iteritems'

On 0.1.15, this is correctly converted. Also, when I remove one ingress block, 0.2.0 also correctly converts it.

virtuald commented 8 years ago

Thanks for the bug report, I might have time to look at this next week.

virtuald commented 8 years ago

@dpetzold perhaps this is a bug that may affect you also at some point? I don't use terraform at all, so I suspect I won't run into it.

virtuald commented 8 years ago

@kvz did #8 fix your issue?

virtuald commented 8 years ago

I'm going to assume it did unless told otherwise. Thanks for the bug report!

kvz commented 8 years ago

Hey that did the trick - thanks so much @elmundio87 and @virtuald! ❤️