Skip to content

fix reconstruction of null #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hcl2/reconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ def _transform_value_to_expr_term(self, value, level) -> Union[Token, Tree]:
)
return Tree(Token("RULE", "expr_term"), [tuple_tree])

if value is None:
return Tree(
Token("RULE", "expr_term"),
[Tree(Token("RULE", "identifier"), [Token("NAME", "null")])],
)

# for dicts, recursively turn the child k/v pairs into object elements
# and store within an object
if isinstance(value, dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{
"terraform": {
"channels": "${local.running_in_ci ? local.ci_channels : local.local_channels}",
"authentication": []
"authentication": [],
"foo": null
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ locals {
terraform = {
channels = (local.running_in_ci ? local.ci_channels : local.local_channels),
authentication = [],
foo = null,
}
}
1 change: 1 addition & 0 deletions test/unit/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_locals_embdedded_condition_tf(self):
terraform={
"channels": "${local.running_in_ci ? local.ci_channels : local.local_channels}",
"authentication": [],
"foo": None,
},
)

Expand Down