You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
reverse_transform not working with variables of type object #231
Describe the bug
I'm using this great library to parse a terraform script, manipulate it and write it back to a .tf file.
I've noticed that parsing a string and reconstructing it does not return the original value, when we have a variable block of type object.
Software:
OS: macOS
Python version 3.13.1
python-hcl2 version 7.2.0
Snippet of HCL2 code causing the unexpected behaviour:
import hcl2
original_string=""" variable "object" { type = object({ key = string value = string }) }"""parsed_hcl=hcl2.loads(original_string, with_meta=True)
ast=hcl2.reverse_transform(parsed_hcl)
reconstructed_string=hcl2.writes(ast)
print(reconstructed_string)
# Prints:# variable "object" {# type = object({"key":"string","value":"string"})# }
Expected behavior
One would expect to get back the original value:
variable "object" {
type = object({
key = string
value = string
})
}
Activity
kkozik-amplify commentedon Apr 7, 2026
Fixed in the latest release:
https://github.com/amplify-education/python-hcl2/releases/tag/v8.1.0