Commit Graph

23 Commits

Author SHA1 Message Date
Tim Gross
1a34c029eb hcl2: avoid panic on unset variable
Variables that are unset return the correct diagnostic but throw a panic when
we later parse the job body. Return early if there are any variable parsing
errors instead of continuing in a potentially invalid state.
2021-02-18 10:48:56 -05:00
Mahmood Ali
2ae4761356 tests: add tests for invalid syntax cases 2021-02-01 12:51:51 -05:00
Mahmood Ali
1e8a3606b7 hcl2: special case meta and env blocks
Allow expressing `meta` and `env` blocks as map attributes as well.
`env` and `meta` should support arbitrary key and values, yet hcl2
restricts the keys to valid identifiers. For example, block attribute
identifiers may not contain dots, `.`, which frequently used in meta
fields, and sometimes in environment variable fields.

This change attempts to parse `env`/`meta` both as an attribute and as a
block.

This additionally allows better expressivity for env/meta blocks, using
functions. For example, one can reuse a set of environment variables for
multiple tasks, using a local common_envs value:

```hcl
env = merge(local.common_envs, {"more_env_key", "..."})
```
2021-02-01 10:45:03 -05:00
Tim Gross
f51d035256 interpolate maps in dynamic blocks (#9921)
Update hcl2 for patch to fix map interpolation in dynamic blocks
2021-01-29 10:16:07 -05:00
Kris Hicks
9ce4077cae jobspec2: decode returns error in more cases (#9613)
Previously, if decoding the job, tasks, or vault portion of the config
failed, we would not return an error; it was silently ignored.

This also includes a little refactor to reduce some duplication.
2020-12-16 07:49:09 -08:00
Kris Hicks
7747124ef0 Apply some suggested fixes from staticcheck (#9598) 2020-12-10 07:29:18 -08:00
Mahmood Ali
f1f473f9a6 appease deadcode linter 2020-11-12 11:44:49 -05:00
Mahmood Ali
a673b8a2bd Restrict HCL special casing of map[string]interface{} fields
The HCL2 parser needs to apply special parsing tweaks so it can parse
the task config the same way as HCL1. Particularly, it needs to
reinterprets `map[string]interface{}` fields and blocks that appear when
attributes are expected.

This commit restricts the special casing to the Job fields, and ignore
`variables` and `locals` block.
2020-11-12 11:35:39 -05:00
Mahmood Ali
c2a6a6da80 use a constructor to initialize job config 2020-11-09 16:27:22 -05:00
Mahmood Ali
21be890256 clarify test 2020-11-09 16:24:22 -05:00
Mahmood Ali
147c8e12c2 clarify variable references 2020-11-09 16:23:09 -05:00
Mahmood Ali
62ee73316e Update variable interpolation tests 2020-11-09 15:03:17 -05:00
Mahmood Ali
a2dff8ed1e Parse variable files 2020-11-09 15:02:21 -05:00
Mahmood Ali
878b3f82fe Restructure Variables and Locals
This reimplements the handling of Variables and Locals in HCL2 config.

This change supports declaring variables and locals, with defaults.
2020-11-09 14:58:57 -05:00
Mahmood Ali
36ad151609 copy variables files from Packer 2020-11-09 14:35:02 -05:00
Chris Baker
9e2eadc7e2 added new policy capabilities for recommendations API
state store: call-out to generic update of job recommendations from job update method
recommendations API work, and http endpoint errors for OSS
support for scaling polices in task block of job spec
add query filters for ScalingPolicy list endpoint
command: nomad scaling policy list: added -job and -type
2020-10-28 14:32:16 +00:00
Mahmood Ali
07240c0b9f hclv2: handle block labels 2020-10-26 16:24:43 -04:00
Mahmood Ali
96c35d8c42 hclv2: special case attributes with map values
HCLv1 special case map assignment:
```hcl
map_attr = { "K" = "V" }
```

is parsed as

```json
{"map_attr": [{"K": "V"}]}
```
2020-10-26 16:20:41 -04:00
Mahmood Ali
4cafcffed5 floats always parsed as float64 2020-10-26 16:20:41 -04:00
Mahmood Ali
18f3f8c776 Refactor handling of blocks as attr 2020-10-26 16:20:41 -04:00
Mahmood Ali
1f949100db hclv2 tests: test complex config configuration 2020-10-26 16:20:41 -04:00
Mahmood Ali
93bbe181e0 address review feedback 2020-10-22 11:49:37 -04:00
Mahmood Ali
7fb6bc3941 Add hclv2 parser 2020-10-21 15:46:56 -04:00