diff --git a/hcl2/reconstructor.py b/hcl2/reconstructor.py index 609a7cce..d36aa26a 100644 --- a/hcl2/reconstructor.py +++ b/hcl2/reconstructor.py @@ -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): diff --git a/test/helpers/terraform-config-json/locals_embedded_condition.json b/test/helpers/terraform-config-json/locals_embedded_condition.json index 5707e562..d8567d1e 100644 --- a/test/helpers/terraform-config-json/locals_embedded_condition.json +++ b/test/helpers/terraform-config-json/locals_embedded_condition.json @@ -3,7 +3,8 @@ { "terraform": { "channels": "${local.running_in_ci ? local.ci_channels : local.local_channels}", - "authentication": [] + "authentication": [], + "foo": null } } ] diff --git a/test/helpers/terraform-config/locals_embedded_condition.tf b/test/helpers/terraform-config/locals_embedded_condition.tf index be718f5d..621adfcf 100644 --- a/test/helpers/terraform-config/locals_embedded_condition.tf +++ b/test/helpers/terraform-config/locals_embedded_condition.tf @@ -2,5 +2,6 @@ locals { terraform = { channels = (local.running_in_ci ? local.ci_channels : local.local_channels), authentication = [], + foo = null, } } diff --git a/test/unit/test_builder.py b/test/unit/test_builder.py index 9ac343a1..419522cc 100644 --- a/test/unit/test_builder.py +++ b/test/unit/test_builder.py @@ -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, }, )