Skip to content

object literal expression parsed in way that can't be serialized #253

@tmccombs

Description

@tmccombs

Describe the bug

In contexts where a map or object is part of an hcl expression, the load or loads function will deserialize as an invalid interpolation.

Software:

  • OS: linux
  • Python version: 3.13 6
  • python-hcl2 version: 7.3.1

Snippet of HCL2 code causing the unexpected behaviour:

locals {
  foo = var.a ? { id = 1 } : null
}

Expected behavior

I expect to get back a valid hcl expression for local.foo, something like

"${var.a ? {id = 1} : null}"

Actual behavior
but instead hcl2.load gives me:

"${var.a ? {'id': 1} : null}"

Notice how the object is setialized like a python dict, not an hcl object.

Then if I try to use reverse_tranaform on it, I get an exception about an unexpected token for the "'".

Metadata

Metadata

Labels

bugSomething isn't workingfixed-in-8.0this issue has been fixed in `transformer-overhaul` feature branch, to be released as v8.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions