From 6983aa2395311cf8f9d5ef297b7d17bcab8dbf61 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 23 Dec 2020 14:54:45 -0600 Subject: [PATCH 1/3] Allow multiline conditionals --- hcl2/hcl2.lark | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hcl2/hcl2.lark b/hcl2/hcl2.lark index 172d8da4..98eed25b 100644 --- a/hcl2/hcl2.lark +++ b/hcl2/hcl2.lark @@ -9,7 +9,7 @@ identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ ?expression : expr_term | operation | conditional -conditional : expression "?" expression ":" expression +conditional : expression "?" new_line_or_comment? expression new_line_or_comment? ":" new_line_or_comment? expression ?operation : unary_op | binary_op !unary_op : ("-" | "!") expr_term From 09ab12da9c8be6fde0b6cdecd8bb732667896a33 Mon Sep 17 00:00:00 2001 From: Alex Oskotsky Date: Wed, 23 Dec 2020 20:52:20 -0500 Subject: [PATCH 2/3] fix transformer and update test --- hcl2/transformer.py | 1 + test/helpers/terraform-config/route_table.tf | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hcl2/transformer.py b/hcl2/transformer.py index db8b7878..b03aaeec 100644 --- a/hcl2/transformer.py +++ b/hcl2/transformer.py @@ -114,6 +114,7 @@ def attribute(self, args: List) -> Dict: } def conditional(self, args: List) -> str: + args = self.strip_new_line_tokens(args) return "%s ? %s : %s" % (args[0], args[1], args[2]) def binary_op(self, args: List) -> str: diff --git a/test/helpers/terraform-config/route_table.tf b/test/helpers/terraform-config/route_table.tf index 831d4244..f74da9b2 100644 --- a/test/helpers/terraform-config/route_table.tf +++ b/test/helpers/terraform-config/route_table.tf @@ -1,5 +1,10 @@ resource "aws_route" "tgw" { - count = var.tgw_name == "" ? 0 : var.number_of_az + count = ( + var.tgw_name == "" ? + 0 : + var.number_of_az + ) + route_table_id = aws_route_table.rt[count.index].id destination_cidr_block = "10.0.0.0/8" transit_gateway_id = data.aws_ec2_transit_gateway.tgw[0].id From e654de3cb688ce5f3ec977555489f1ca56524812 Mon Sep 17 00:00:00 2001 From: Alex Oskotsky Date: Wed, 23 Dec 2020 20:56:41 -0500 Subject: [PATCH 3/3] update version and changelog --- CHANGELOG.md | 5 +++++ hcl2/version.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e9e931..5b9d89f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## \[2.0.1] - 2020-12-24 + +### Changed +- Allow multiline conditional statements. Thanks @stpierre ([#51](https://github.com/amplify-education/python-hcl2/pull/51)) + ## \[2.0.0] - 2020-11-02 ### Changed diff --git a/hcl2/version.py b/hcl2/version.py index 52f98344..0c118792 100644 --- a/hcl2/version.py +++ b/hcl2/version.py @@ -1,3 +1,3 @@ """Place of record for the package version""" -__version__ = "2.0.0" +__version__ = "2.0.1"