| 1 |
# |
| 2 |
# This syntax definition is based on the Terraform guide: |
| 3 |
# https://www.terraform.io/docs/configuration/index.html |
| 4 |
# |
| 5 |
# Formatting is loosely based on Sublime's and VSCode's syntax highlighting for Terraform: |
| 6 |
# https://github.com/totoroot/Terraform.tmLanguage/blob/master/Terraform.sublime-syntax |
| 7 |
# https://github.com/hashicorp/vscode-terraform/blob/main/syntaxes/terraform.tmGrammar.json |
| 8 |
# |
| 9 |
|
| 10 |
filetype: terraform |
| 11 |
|
| 12 |
detect: |
| 13 |
# File Extensions: |
| 14 |
# |
| 15 |
# - ".tf": the standard file extension |
| 16 |
# https://www.terraform.io/docs/configuration/index.html#code-organization |
| 17 |
# |
| 18 |
# - ".hcl": non-terraform tools often use this HCL syntax, i.e. Vault |
| 19 |
# https://www.vaultproject.io/docs/configuration/ |
| 20 |
filename: "\\.tf$|\\.hcl$" |
| 21 |
|
| 22 |
rules: |
| 23 |
# Named Values |
| 24 |
# |
| 25 |
# https://www.terraform.io/docs/language/expressions/references.html |
| 26 |
- identifier: "\\b(var|local|module|data|path|terraform)\\b" |
| 27 |
|
| 28 |
# Block types |
| 29 |
# |
| 30 |
# resource: https://www.terraform.io/docs/language/resources/syntax.html |
| 31 |
# provider: https://www.terraform.io/docs/language/providers/configuration.html |
| 32 |
# variable: https://www.terraform.io/docs/language/values/variables.html |
| 33 |
# output: https://www.terraform.io/docs/language/values/outputs.html |
| 34 |
# locals: https://www.terraform.io/docs/language/values/locals.html |
| 35 |
# module: https://www.terraform.io/docs/language/modules/syntax.html |
| 36 |
# data: https://www.terraform.io/docs/language/data-sources/index.html |
| 37 |
# terraform: https://www.terraform.io/docs/language/settings/index.html#terraform-block-syntax |
| 38 |
- special: "\\b(resource|provider|variable|output|locals|module|terraform)\\b" |
| 39 |
|
| 40 |
# Built-In type keywords |
| 41 |
# |
| 42 |
# https://www.terraform.io/docs/language/expressions/type-constraints.html#primitive-types |
| 43 |
# https://www.terraform.io/docs/language/expressions/type-constraints.html#dynamic-types-the-quot-any-quot-constraint |
| 44 |
- type.keyword: "\\b(any|string|number|bool)\\b" |
| 45 |
|
| 46 |
# Built-In Functions |
| 47 |
# |
| 48 |
# https://www.terraform.io/docs/language/functions/index.html |
| 49 |
- statement: "\\b(abs|ceil|floor|log|max|min|parseint|pow|signum|chomp|format|formatlist|indent|join|lower|regex|regexall|replace|split|strrev|substr|title|trim|trimprefix|trimsuffix|trimspace|upper|alltrue|anytrue|chunklist|coalesce|coalescelist|compact|concat|contains|distinct|element|flatten|index|keys|length|list|lookup|map|matchkeys|merge|one|range|reverse|setintersection|setproduct|setsubtract|setunion|slice|sort|sum|transpose|values|zipmap|base64decode|base64encode|base64gzip|csvdecode|jsondecode|jsonencode|textdecodebase64|textencodebase64|urlencode|yamldecode|yamlencode|abspath|dirname|pathexpand|basename|file|fileexists|fileset|filebase64|templatefile|formatdate|timeadd|timestamp|base64sha256|base64sha512|bcrypt|filebase64sha256|filebase64sha512|filemd5|filesha1|filesha256|filesha512|md5|rsadecrypt|sha1|sha256|sha512|uuid|uuidv5|cidrhost|cidrnetmask|cidrsubnet|cidrsubnets|can|defaults|nonsensitive|sensitive|tobool|tolist|tomap|tonumber|toset|tostring|try)\\b" |
| 50 |
|
| 51 |
- symbol.operator: "([~^.:;,+*|=!\\%@]|<|>|/|-|&)" |
| 52 |
|
| 53 |
- symbol.brackets: "([(){}]|\\[|\\])" |
| 54 |
|
| 55 |
- constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b|'.'" |
| 56 |
|
| 57 |
- constant.bool: "\\b(true|false|null)\\b" |
| 58 |
|
| 59 |
- constant.string: |
| 60 |
start: "\"" |
| 61 |
end: "\"" |
| 62 |
skip: "\\\\." |
| 63 |
rules: |
| 64 |
- constant.specialChar: "%." |
| 65 |
- constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]" |
| 66 |
- constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" |
| 67 |
|
| 68 |
- constant.string: |
| 69 |
start: "''" |
| 70 |
end: "''" |
| 71 |
skip: "\\\\." |
| 72 |
rules: |
| 73 |
- constant.specialChar: "%." |
| 74 |
- constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]" |
| 75 |
- constant.specialChar: "\\\\([0-7]{3}|x[A-Fa-f0-9]{2}|u[A-Fa-f0-9]{4}|U[A-Fa-f0-9]{8})" |
| 76 |
|
| 77 |
- comment: |
| 78 |
start: "#|//" |
| 79 |
end: "$\\n?" |
| 80 |
rules: |
| 81 |
- todo: "(TODO|XXX|FIXME):?" |
| 82 |
|
| 83 |
- comment: |
| 84 |
start: "/\\*" |
| 85 |
end: "\\*/" |
| 86 |
rules: |
| 87 |
- todo: "(TODO|XXX|FIXME):?" |