Describe the bug
import sys
import hcl2
print(hcl2.writes(hcl2.parse(sys.stdin))
Running the above code on the following snippet
locals {
foo = "bar" # Foo
baz = "biz"
spam = egg([
"arg-1",
"arg-2",
])
}
produces the following output.
locals {
foo = "bar"# Foo
baz = "biz"
spam = egg([
"arg-1",
"arg-2"
])
}
The issues are:
- Spaces around the comment are no longer present.
- Trailing comma is missing in the array.
Software:
- OS: Linux
- Python version: 3.13.12
- python-hcl2 version: 7.3.1
Snippet of HCL2 code causing the unexpected behaviour:
locals {
foo = "bar" # Foo
baz = "biz"
spam = egg([
"arg-1",
"arg-2",
])
}
Expected behavior
The exact input is produced since the AST is not modified.
Exception traceback (if applicable):
N/A