github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/syntax.mdx (about) 1 --- 2 layout: docs 3 page_title: Syntax - Configuration Language 4 description: |- 5 HCL has its own syntax, intended to combine declarative 6 structure with expressions in a way that is easy for humans to read and 7 understand. 8 --- 9 10 # HCL Configuration Syntax 11 12 Other pages in this section have described various configuration constructs 13 that can appear in HCL. This page describes the lower-level syntax of the 14 language in more detail, revealing the building blocks that those constructs 15 are built from. 16 17 This page describes the _native syntax_ of HCL, which is a rich language 18 designed to be easy for humans to read and write. 19 20 This low-level syntax of HCL is defined in terms of a syntax called _HCL_, 21 which is also used by configuration languages in other applications, and in 22 particular other HashiCorp products. It is not necessary to know all of the 23 details of HCL in order to use Nomad, and so this page summarizes the most 24 important details. If you are interested, you can find a full definition of HCL 25 syntax in [the HCL native syntax 26 specification](https://github.com/hashicorp/hcl/blob/hcl2/hclsyntax/spec.md). 27 28 ## Arguments and Blocks 29 30 HCL syntax is built around two key syntax constructs: 31 arguments and blocks. 32 33 ### Arguments 34 35 An _argument_ assigns a value to a particular name: 36 37 ```hcl 38 image_id = "nginx:1.19" 39 ``` 40 41 The identifier before the equals sign is the _argument name_, and the expression 42 after the equals sign is the argument's value. 43 44 The context where the argument appears determines what value types are valid 45 (for example, each job block type has a schema that defines the types of its 46 arguments), but many arguments accept arbitrary 47 [expressions](/docs/job-specification/hcl2/expressions), which allow the value to 48 either be specified literally or generated from other values programmatically. 49 50 ### Blocks 51 52 A _block_ is a container for other content: 53 54 ```hcl 55 task "webserver" { 56 driver = "docker" 57 58 config { 59 # ... 60 } 61 } 62 ``` 63 64 A block has a _type_ (`task` in this example). Each block type defines 65 how many _labels_ must follow the type keyword. The `task` block type 66 expects one label, which is `webserver` in the example above. 67 A particular block type may have any number of required labels, or it may 68 require none as with the nested `config` block type. 69 70 After the block type keyword and any labels, the block _body_ is delimited 71 by the `{` and `}` characters. Within the block body, further arguments 72 and blocks may be nested, creating a hierarchy of blocks and their associated 73 arguments. 74 75 HCL uses a limited number of _top-level block types,_ which 76 are blocks that can appear outside of any other block in a configuration file. 77 78 ## Identifiers 79 80 Argument names, block type names, and the names of most Nomad-specific 81 constructs like tasks, input variables, etc. are all _identifiers_. 82 83 Identifiers can contain letters, digits, underscores (`_`), and hyphens (`-`). 84 The first character of an identifier must not be a digit, to avoid ambiguity 85 with literal numbers. 86 87 For complete identifier rules, Nomad implements 88 [the Unicode identifier syntax](http://unicode.org/reports/tr31/), extended to 89 include the ASCII hyphen character `-`. 90 91 ## Comments 92 93 HCL supports three different syntaxes for comments: 94 95 - `#` begins a single-line comment, ending at the end of the line. 96 - `//` also begins a single-line comment, as an alternative to `#`. 97 - `/*` and `*/` are start and end delimiters for a comment that might span 98 over multiple lines. 99 100 The `#` single-line comment style is the default comment style and should be 101 used in most cases. Automatic configuration formatting tools may automatically 102 transform `//` comments into `#` comments, since the double-slash style is 103 not idiomatic. 104 105 ## Character Encoding and Line Endings 106 107 Nomad configuration files must always be UTF-8 encoded. While the 108 delimiters of the language are all ASCII characters, Nomad accepts 109 non-ASCII characters in identifiers, comments, and string values. 110 111 Nomad accepts configuration files with either Unix-style line endings 112 (LF only) or Windows-style line endings (CR then LF), but the idiomatic style 113 is to use the Unix convention, and so automatic configuration formatting tools 114 may automatically transform CRLF endings to LF.