Skip to content

Regression in 8.1.0: null values serialized as "null" strings (works in 7.3.1) #293

Description

@ernestoalarcongallo

Hi maintainers, thanks for your work on python-hcl2.

Environment:

python-hcl2: 8.1.0
Last known working version: 7.3.1

Summary:

After upgrading to 8.1.0, parsing/serialization appears to preserve quote characters in a way that changes value types. In our Terraform tfvars JSON output, null values become the string "null", which then breaks Terraform type validation.

Observed error:

Error: Region is not valid: "us-east-1"

And during Terraform plan:
Error: Invalid value for input variable
a number is required

Problematic generated values:

ecs_autoscaling_replicas: "null"
ecs_autoscaling_target_cpu_utilization: "null"
ecs_autoscaling_target_ram_utilization: "null"

Expected behavior:

These values should remain null (JSON null), not "null" (string), so Terraform can treat them as nullable numeric inputs.

Compatibility attempt:

We tried the migration-guide compatibility options:

V7_COMPAT = SerializationOptions(
strip_string_quotes=True,
explicit_blocks=False,
with_comments=False,
)

With these options, the null-to-"null" issue still occurs.

Impact:

Terraform planning fails because variables expecting numbers receive strings.

Request:

Could you please confirm whether this is a known regression in 8.1.0 and advise on a workaround? Happy to provide a minimal reproducer if needed.

Thanks a lot.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workinggrammarIssue is related to HCL2 grammar definitionregressionSomething broke in a new versionround-tripFull-cycle parse/serialize/deserialize fidelity

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions