Skip to content

Commit fd25b05

Browse files
committed
Prepare to release 0.2.2
1 parent 30f8915 commit fd25b05

7 files changed

Lines changed: 103 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 0.2.2
4+
5+
- Added sensitive variable support
6+
- Fixed provider block inside required_providers
7+
38
## 0.2.1
49

510
- Added variable validation support ([#5](https://github.com/4ops/vscode-language-terraform/issues/5))

examples/locals.tf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,51 @@ locals {
5454
data.template.rendered,
5555
]))
5656
}
57+
58+
variable "example" {
59+
type = any
60+
}
61+
62+
locals {
63+
example = try(
64+
[tostring(var.example)],
65+
tolist(var.example),
66+
)
67+
}
68+
69+
locals {
70+
raw_value = yamldecode(file("${path.module}/example.yaml"))
71+
normalized_value = {
72+
name = tostring(try(local.raw_value.name, null))
73+
groups = try(local.raw_value.groups, [])
74+
}
75+
}
76+
77+
locals {
78+
storage = defaults(var.storage, {
79+
# If "enabled" isn't set then it will default
80+
# to true.
81+
enabled = true
82+
83+
# The "website" attribute is required, but
84+
# it's here to provide defaults for the
85+
# optional attributes inside.
86+
website = {
87+
index_document = "index.html"
88+
error_document = "error.html"
89+
}
90+
91+
# The "documents" attribute has a map type,
92+
# so the default value represents defaults
93+
# to be applied to all of the elements in
94+
# the map, not for the map itself. Therefore
95+
# it's a single object matching the map
96+
# element type, not a map itself.
97+
documents = {
98+
# If _any_ of the map elements omit
99+
# content_type then this default will be
100+
# used instead.
101+
content_type = "application/octet-stream"
102+
}
103+
})
104+
}

examples/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ output "fqdn" {
2222
description = "lasjdkaslkdjalksjdlkjaskd"
2323
}
2424

25+
output "sensitive_example_hash" {
26+
value = nonsensitive(sha256(var.sensitive_example))
27+
}

examples/terraform.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ terraform {
77
template = ">= 2.1"
88
tls = "~> 2.0"
99
null = "~> 2.1"
10+
11+
digitalocean = {
12+
source = "digitalocean/digitalocean"
13+
}
1014
}
1115

1216
backend "s3" {

examples/variables.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,33 @@ variable "ipv6" {
8989
description = <<-DESCRIPTION
9090
Bitcoin extra arguments for testnet.
9191
DESCRIPTION
92+
93+
sensitive = true
94+
}
95+
96+
variable "timestamp" {
97+
type = string
98+
99+
validation {
100+
# formatdate fails if the second argument is not a valid timestamp
101+
condition = can(formatdate("", var.timestamp))
102+
error_message = "The timestamp argument requires a valid RFC 3339 timestamp."
103+
}
104+
}
105+
106+
variable "storage" {
107+
type = object({
108+
name = string
109+
enabled = optional(bool)
110+
website = object({
111+
index_document = optional(string)
112+
error_document = optional(string)
113+
})
114+
documents = map(
115+
object({
116+
source_file = string
117+
content_type = optional(string)
118+
})
119+
)
120+
})
92121
}

grammars/tf.yaml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,19 @@ patterns:
3535
- name: "meta.terraform.required_providers.tf"
3636
begin: '\b(required_providers)([\w\-\"$])?(?:\s+)?({)'
3737
beginCaptures:
38-
# 1: { name: keyword.control.$1.tf }
38+
1: { name: keyword.declaration.$1.tf }
3939
2: { name: invalid.illegal.keyword.$1.tf }
40-
3: { name: punctuation.definition.block.begin.tf }
40+
3: { name: punctuation.declaration.block.begin.tf }
4141
end: "}"
4242
endCaptures:
4343
0: { name: punctuation.definition.block.end.tf }
4444
patterns:
4545
- include: "#comments"
46-
- match: '\b([\-\w]+)(?:\s+)?(=)(?:\s+)?(")([^$"]+)?(")'
46+
- match: '\b([\-\w]+)(?:\s+)?(=)(?:\s+)?'
4747
captures:
48-
1: { name: entity.name.provider.tf }
48+
1: { name: support.provider.attribute.tf }
4949
2: { name: keyword.operator.assignment.tf }
50-
3:
51-
{
52-
name: string.quoted.double.tf punctuation.definition.string.begin.tf,
53-
}
54-
4: { name: string.quoted.double.tf }
55-
5:
56-
{
57-
name: string.quoted.double.tf punctuation.definition.string.end.tf,
58-
}
50+
- include: "#definition-right"
5951
- name: "meta.terraform.backend.tf"
6052
begin: '\b(backend)(?:\s+)?(")([^$"]+)?(")(?:\s+)?({)'
6153
beginCaptures:
@@ -169,7 +161,7 @@ patterns:
169161
0: { name: punctuation.declaration.block.end.tf }
170162
patterns:
171163
- include: "#comments"
172-
- match: '\b(type|default|description|validation)(?:\s+)?(=)?(?:\s+)?'
164+
- match: '\b(type|default|description|validation|sensitive)(?:\s+)?(=)?(?:\s+)?'
173165
captures:
174166
1: { name: meta.keyword.$1.tf }
175167
2: { name: keyword.operator.assignment.tf }
@@ -365,11 +357,11 @@ repository:
365357

366358
support-function-collection:
367359
name: support.function.builtin.collection.tf
368-
match: '(?<!\.)\b(chunklist|coalescelist|coalesce|compact|concat|contains|distinct|element|flatten|index|keys|length|list|lookup|map|matchkeys|merge|range|reverse|setintersection|setproduct|setunion|slice|sort|transpose|values|zipmap)\b(?=\()'
360+
match: '(?<!\.)\b(alltrue|anytrue|chunklist|coalescelist|coalesce|compact|concat|contains|distinct|element|flatten|index|keys|length|list|lookup|map|matchkeys|merge|one|range|reverse|setintersection|setproduct|setsubtract|setunion|slice|sort|transpose|values|zipmap)\b(?=\()'
369361

370362
support-function-encoding:
371363
name: support.function.builtin.encoding.tf
372-
match: '(?<!\.)\b(base64decode|base64encode|base64gzip|csvdecode|jsondecode|jsonencode|urlencode|yamldecode|yamlencode)\b(?=\()'
364+
match: '(?<!\.)\b(base64decode|base64encode|base64gzip|csvdecode|jsondecode|jsonencode|textdecodebase64|textencodebase64|urlencode|yamldecode|yamlencode)\b(?=\()'
373365

374366
support-function-filesystem:
375367
name: support.function.builtin.filesystem.tf
@@ -389,7 +381,7 @@ repository:
389381

390382
support-function-conversion:
391383
name: support.function.builtin.conversion.tf
392-
match: '(?<!\.)\b(tobool|tolist|tomap|tonumber|toset|tostring)\b(?=\()'
384+
match: '(?<!\.)\b(can|defaults|nonsensitive|sensitive|tobool|tolist|tomap|tonumber|toset|tostring|try)\b(?=\()'
393385

394386
constants-decimal:
395387
match: '\b\d+(\.)?(\d+)?'
@@ -418,7 +410,7 @@ repository:
418410
name: keyword.operator.ternary.tf
419411

420412
keyword-comparison:
421-
match: "~>|>=|<=|==|!=|[^<]<[^<]|[^>]>[^>]"
413+
match: '\b(~>|>=|<=|==|!=|[^<]<[^<]|[^>]>[^>])'
422414
name: keyword.operator.comparison.tf
423415

424416
keyword-conditional:

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@
9898
},
9999
"scripts": {
100100
"build": "npm run compile -s",
101-
"compile-tf": "yq r --prettyPrint --tojson grammars/tf.yaml > grammars/tf.json",
102-
"compile-tfvars": "yq r --prettyPrint --tojson grammars/tfvars.yaml > grammars/tfvars.json",
103-
"compile-terragrunt": "yq r --prettyPrint --tojson grammars/terragrunt.yaml > grammars/terragrunt.json",
104-
"compile-snippets": "yq r --prettyPrint --tojson snippets/tf.yaml > snippets/tf.json",
101+
"compile-tf": "yq eval --prettyPrint --tojson grammars/tf.yaml > grammars/tf.json",
102+
"compile-tfvars": "yq eval --prettyPrint --tojson grammars/tfvars.yaml > grammars/tfvars.json",
103+
"compile-terragrunt": "yq eval --prettyPrint --tojson grammars/terragrunt.yaml > grammars/terragrunt.json",
104+
"compile-snippets": "yq eval --prettyPrint --tojson snippets/tf.yaml > snippets/tf.json",
105105
"compile": "npm run compile-tf && npm run compile-tfvars && npm run compile-terragrunt && npm run compile-snippets",
106106
"preversion": "git add -A .",
107107
"postversion": "npm run push -s",

0 commit comments

Comments
 (0)