From 92f2ee22b26f81e72b43210f5f0e9e83a193cee3 Mon Sep 17 00:00:00 2001 From: Kamil Kozik <115631738+kkozik-amplify@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:16:59 +0200 Subject: [PATCH] allow `if` and `for_each` keywords to be used as identifiers (#168) --- hcl2/hcl2.lark | 4 +++- .../resource_in_attribute.json | 13 ------------- ...tribute.json => resource_keyword_attribute.json} | 5 ++++- .../terraform-config/resource_for_attribute.tf | 5 ----- .../terraform-config/resource_in_attribute.tf | 5 ----- .../terraform-config/resource_keyword_attribute.tf | 8 ++++++++ 6 files changed, 15 insertions(+), 25 deletions(-) delete mode 100644 test/helpers/terraform-config-json/resource_in_attribute.json rename test/helpers/terraform-config-json/{resource_for_attribute.json => resource_keyword_attribute.json} (55%) delete mode 100644 test/helpers/terraform-config/resource_for_attribute.tf delete mode 100644 test/helpers/terraform-config/resource_in_attribute.tf create mode 100644 test/helpers/terraform-config/resource_keyword_attribute.tf diff --git a/hcl2/hcl2.lark b/hcl2/hcl2.lark index ea2fd80..0d6b40b 100644 --- a/hcl2/hcl2.lark +++ b/hcl2/hcl2.lark @@ -5,9 +5,11 @@ block : identifier (identifier | STRING_LIT)* new_line_or_comment? "{" body "}" new_line_and_or_comma: new_line_or_comment | "," | "," new_line_or_comment new_line_or_comment: ( /\n/ | /#.*\n/ | /\/\/.*\n/ )+ -identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ | IN | FOR +identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/ | IN | FOR | IF | FOR_EACH +IF : "if" IN : "in" FOR : "for" +FOR_EACH : "for_each" ?expression : expr_term | operation | conditional diff --git a/test/helpers/terraform-config-json/resource_in_attribute.json b/test/helpers/terraform-config-json/resource_in_attribute.json deleted file mode 100644 index f94f842..0000000 --- a/test/helpers/terraform-config-json/resource_in_attribute.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "resource": [ - { - "custom_provider_resource": { - "resource_name": { - "name": "resource_name", - "attribute": "attribute_value", - "in": "attribute_value2" - } - } - } - ] -} diff --git a/test/helpers/terraform-config-json/resource_for_attribute.json b/test/helpers/terraform-config-json/resource_keyword_attribute.json similarity index 55% rename from test/helpers/terraform-config-json/resource_for_attribute.json rename to test/helpers/terraform-config-json/resource_keyword_attribute.json index 5144592..11ff88f 100644 --- a/test/helpers/terraform-config-json/resource_for_attribute.json +++ b/test/helpers/terraform-config-json/resource_keyword_attribute.json @@ -5,7 +5,10 @@ "resource_name": { "name": "resource_name", "attribute": "attribute_value", - "for": "attribute_value2" + "if" : "attribute_value2", + "in" : "attribute_value3", + "for" : "attribute_value4", + "for_each" : "attribute_value5" } } } diff --git a/test/helpers/terraform-config/resource_for_attribute.tf b/test/helpers/terraform-config/resource_for_attribute.tf deleted file mode 100644 index 3478644..0000000 --- a/test/helpers/terraform-config/resource_for_attribute.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "custom_provider_resource" "resource_name" { - name = "resource_name" - attribute = "attribute_value" - for = "attribute_value2" -} diff --git a/test/helpers/terraform-config/resource_in_attribute.tf b/test/helpers/terraform-config/resource_in_attribute.tf deleted file mode 100644 index 85052f0..0000000 --- a/test/helpers/terraform-config/resource_in_attribute.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "custom_provider_resource" "resource_name" { - name = "resource_name" - attribute = "attribute_value" - in = "attribute_value2" -} diff --git a/test/helpers/terraform-config/resource_keyword_attribute.tf b/test/helpers/terraform-config/resource_keyword_attribute.tf new file mode 100644 index 0000000..fca27d7 --- /dev/null +++ b/test/helpers/terraform-config/resource_keyword_attribute.tf @@ -0,0 +1,8 @@ +resource "custom_provider_resource" "resource_name" { + name = "resource_name" + attribute = "attribute_value" + if = "attribute_value2" + in = "attribute_value3" + for = "attribute_value4" + for_each = "attribute_value5" +}