From c4982be7dbf6e94ad75c9a3740040d4e4b9bc2a4 Mon Sep 17 00:00:00 2001 From: ibutskhrikidze Date: Wed, 24 May 2023 09:42:11 +0400 Subject: [PATCH] support conditional without parentheses inside nested locals --- hcl2/hcl2.lark | 2 +- .../locals_embedded_condition.json | 10 ++++++++++ .../terraform-config/locals_embedded_condition.tf | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/helpers/terraform-config-json/locals_embedded_condition.json create mode 100644 test/helpers/terraform-config/locals_embedded_condition.tf diff --git a/hcl2/hcl2.lark b/hcl2/hcl2.lark index f82b6228..b9e453c7 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 "?" new_line_or_comment? expression new_line_or_comment? ":" new_line_or_comment? expression new_line_or_comment? +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 diff --git a/test/helpers/terraform-config-json/locals_embedded_condition.json b/test/helpers/terraform-config-json/locals_embedded_condition.json new file mode 100644 index 00000000..5707e562 --- /dev/null +++ b/test/helpers/terraform-config-json/locals_embedded_condition.json @@ -0,0 +1,10 @@ +{ + "locals": [ + { + "terraform": { + "channels": "${local.running_in_ci ? local.ci_channels : local.local_channels}", + "authentication": [] + } + } + ] +} diff --git a/test/helpers/terraform-config/locals_embedded_condition.tf b/test/helpers/terraform-config/locals_embedded_condition.tf new file mode 100644 index 00000000..55b57b35 --- /dev/null +++ b/test/helpers/terraform-config/locals_embedded_condition.tf @@ -0,0 +1,6 @@ +locals { + terraform = { + channels = local.running_in_ci ? local.ci_channels : local.local_channels + authentication = [] + } +}