aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/ext/typeexpr/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/ext/typeexpr/README.md')
-rw-r--r--vendor/github.com/hashicorp/hcl2/ext/typeexpr/README.md67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/ext/typeexpr/README.md b/vendor/github.com/hashicorp/hcl2/ext/typeexpr/README.md
new file mode 100644
index 0000000..ff2b3f2
--- /dev/null
+++ b/vendor/github.com/hashicorp/hcl2/ext/typeexpr/README.md
@@ -0,0 +1,67 @@
1# HCL Type Expressions Extension
2
3This HCL extension defines a convention for describing HCL types using function
4call and variable reference syntax, allowing configuration formats to include
5type information provided by users.
6
7The type syntax is processed statically from a hcl.Expression, so it cannot
8use any of the usual language operators. This is similar to type expressions
9in statically-typed programming languages.
10
11```hcl
12variable "example" {
13 type = list(string)
14}
15```
16
17The extension is built using the `hcl.ExprAsKeyword` and `hcl.ExprCall`
18functions, and so it relies on the underlying syntax to define how "keyword"
19and "call" are interpreted. The above shows how they are interpreted in
20the HCL native syntax, while the following shows the same information
21expressed in JSON:
22
23```json
24{
25 "variable": {
26 "example": {
27 "type": "list(string)"
28 }
29 }
30}
31```
32
33Notice that since we have additional contextual information that we intend
34to allow only calls and keywords the JSON syntax is able to parse the given
35string directly as an expression, rather than as a template as would be
36the case for normal expression evaluation.
37
38For more information, see [the godoc reference](http://godoc.org/github.com/hashicorp/hcl2/ext/typeexpr).
39
40## Type Expression Syntax
41
42When expressed in the native syntax, the following expressions are permitted
43in a type expression:
44
45* `string` - string
46* `bool` - boolean
47* `number` - number
48* `any` - `cty.DynamicPseudoType` (in function `TypeConstraint` only)
49* `list(<type_expr>)` - list of the type given as an argument
50* `set(<type_expr>)` - set of the type given as an argument
51* `map(<type_expr>)` - map of the type given as an argument
52* `tuple([<type_exprs...>])` - tuple with the element types given in the single list argument
53* `object({<attr_name>=<type_expr>, ...}` - object with the attributes and corresponding types given in the single map argument
54
55For example:
56
57* `list(string)`
58* `object({name=string,age=number})`
59* `map(object({name=string,age=number}))`
60
61Note that the object constructor syntax is not fully-general for all possible
62object types because it requires the attribute names to be valid identifiers.
63In practice it is expected that any time an object type is being fixed for
64type checking it will be one that has identifiers as its attributes; object
65types with weird attributes generally show up only from arbitrary object
66constructors in configuration files, which are usually treated either as maps
67or as the dynamic pseudo-type.