From 9573c0c79f43077272df3d6d9bce78fa2d04aa9d Mon Sep 17 00:00:00 2001 From: isaac-coles Date: Thu, 15 Jun 2023 10:38:13 +1000 Subject: [PATCH] add: new checks syntax highlighting --- examples/main.tf | 11 +++++++++++ grammars/tf.yaml | 36 ++++++++++++++++++++++++++++++++++++ snippets/tf.yaml | 17 +++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/examples/main.tf b/examples/main.tf index 3bf23d5..83e5323 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -20,3 +20,14 @@ module "vpc" { tags = local.tags } + +check "health_check" { + data "http" "terraform_io" { + url = "https://www.terraform.io" + } + + assert { + condition = data.http.terraform_io.status_code == 200 + error_message = "${data.http.terraform_io.url} returned an unhealthy status code" + } +} \ No newline at end of file diff --git a/grammars/tf.yaml b/grammars/tf.yaml index 7793d8e..fdc3fda 100644 --- a/grammars/tf.yaml +++ b/grammars/tf.yaml @@ -208,6 +208,42 @@ patterns: 1: { name: support.output.attribute.tf } 2: { name: keyword.operator.assignment.tf } - include: "#definition-right" + + - name: "meta.check.tf" + begin: '\b(check)([\w\-\"$])?(?:\s+)?(")?([^\"\n]+)?(")?(?:\s+)?({)' + beginCaptures: + 1: { name: keyword.declaration.$1.tf } + 2: { name: invalid.illegal.keyword.$1.tf } + 3: + { name: string.quoted.double.tf punctuation.definition.string.begin.tf } + 4: { name: string.quoted.double.tf entity.name.$1.tf } + 5: { name: string.quoted.double.tf punctuation.definition.string.end.tf } + 6: { name: punctuation.declaration.block.begin.tf } + end: "}" + endCaptures: + 0: { name: punctuation.declaration.block.end.tf } + patterns: + - include: "#comments" + - match: '\b(data)(?:\s+)?(=)?(?:\s+)?' + captures: + 1: { name: keyword.declaration.$1.tf } + 2: { name: invalid.illegal.keyword.$1.tf } + 3: + { name: string.quoted.double.tf punctuation.definition.string.begin.tf } + 4: { name: string.quoted.double.tf entity.type.$1.tf } + 5: { name: string.quoted.double.tf punctuation.definition.string.end.tf } + 6: + { name: string.quoted.double.tf punctuation.definition.string.begin.tf } + 7: { name: string.quoted.double.tf entity.name.$1.tf } + 8: { name: string.quoted.double.tf punctuation.definition.string.end.tf } + 9: { name: punctuation.declaration.block.begin.tf } + - match: '\b(assert)(?:\s+)?(=)?(?:\s+)?' + captures: + 1: { name: meta.keyword.$1.tf } + 2: { name: keyword.operator.assignment.tf } + - include: "#definition-right" + - match: '\S' + name: invalid.illegal.keyword.variable.tf - name: "meta.data.tf" begin: '\b(data)([\w\-\"$])?(?:\s+)?(")?([^\"\n]+)?(")?(?:\s+)?(")?([^\"\n]+)?(")?(?:\s+)?({)' diff --git a/snippets/tf.yaml b/snippets/tf.yaml index b6e2edd..1a8c1a7 100644 --- a/snippets/tf.yaml +++ b/snippets/tf.yaml @@ -142,6 +142,23 @@ Data http: } } +Check http: +Variable: + scope: source.tf + prefix: check-http + description: Input variable. + body: | + check ${1:name} { + data http ${2:name} { + url = ${3|"https://","http://",var.,data.,local.,module.|} + } + + assert { + condition = ${4:boolean_expression} + error_message = ${5:error_string} + } + } + # --- Provider: Terraform Data from remote terraform state: