feat(hcl): add additional queries

* index
* for expressions
* arithmetic and logical expressions
* escape sequences inside string template
This commit is contained in:
Hoang Nguyen 2023-11-20 00:00:00 +07:00
parent 32a30136c2
commit 6906560814
No known key found for this signature in database
GPG key ID: B0567C20730E9B11
2 changed files with 71 additions and 0 deletions

View file

@ -2,10 +2,30 @@
(tuple_start "[") @delimiter
(tuple_end "]") @delimiter @sentinel) @container
(for_tuple_expr
(tuple_start "[") @delimiter
(tuple_end "]") @delimiter @sentinel) @container
(new_index
"[" @delimiter
"]" @delimiter @sentinel) @container
(function_call
"(" @delimiter
")" @delimiter @sentinel) @container
(expression
"(" @delimiter
")" @delimiter @sentinel) @container
(binary_operation
"(" @delimiter
")" @delimiter @sentinel) @container
(unary_operation
"(" @delimiter
")" @delimiter @sentinel) @container
(block
(block_start "{") @delimiter
(block_end "}") @delimiter @sentinel) @container
@ -13,3 +33,15 @@
(object
(object_start "{") @delimiter
(object_end "}") @delimiter @sentinel) @container
(for_object_expr
(object_start "{") @delimiter
(object_end "}") @delimiter @sentinel) @container
(template_interpolation
(template_interpolation_start) @delimiter
(template_interpolation_end) @delimiter @sentinel) @container
(_
(template_directive_start) @delimiter
(template_directive_end) @delimiter @sentinel) @container

View file

@ -30,4 +30,43 @@ resource "provider_grant" "usage_grants" {
roles = [provider_role.role2.name]
}
resource "example" "binary_expressions" {
cond1 = (0*1) ? 1 : "foobar"
bin1 = ((!(1)+2)%3)*4
}
resource "example" "for_expressions" {
for1 = { for i, v in ["a", "a", "b"] : v => i... }
for2 = [ for k, v in x : "${k}-${v}" ]
}
variable "timestamp" {
type = string
validation {
# formatdate fails if the second argument is not a valid timestamp
condition = can(formatdate("", var.timestamp))
error_message = "Hello, %{ if var.name != "" }${var.name}%{ else }unnamed%{ endif }!"
}
}
block {
sample = <<-EOT
%{ for ip in aws_instance.example[*].private_ip }
server ${ip}
%{ endfor }
EOT
}
resource "terraform_data" "cluster" {
# Replacement of any instance of the cluster requires re-provisioning
triggers_replace = aws_instance.cluster.[*].id
# Bootstrap script can run on any instance of the cluster
# So we just choose the first in this case
connection {
host = aws_instance.cluster.[0].public_ip
}
}
# vim:ft=hcl