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