opentofu/vendor/github.com/hashicorp/hil
2019-02-12 15:56:22 +00:00
..
ast govendor fetch github.com/hashicorp/hil/... 2017-05-04 15:56:35 -07:00
parser vendor: update HIL 2016-12-09 12:40:34 -05:00
scanner vendor: govendor fetch github.com/hashicorp/hil/... 2017-07-03 11:08:09 -07:00
.gitignore vendor: update to latest github.com/zclconf/go-cty 2018-10-16 19:14:11 -07:00
.travis.yml vendor: update to latest github.com/zclconf/go-cty 2018-10-16 19:14:11 -07:00
appveyor.yml deps: Update github.com/hashicorp/hil 2016-03-23 05:14:43 -07:00
builtins.go vendor: update HIL with conditionals 2016-12-07 18:13:48 -05:00
check_identifier.go deps: Update github.com/hashicorp/hil/... 2016-04-18 16:31:19 -07:00
check_types.go Update HIL vendor for conditional type checking fix 2017-05-12 15:23:12 -07:00
convert.go vendor: github.com/hashicorp/hil@latest 2019-02-12 15:56:22 +00:00
eval_type.go vendor: update HIL 2016-11-13 10:28:26 -08:00
eval.go govendor fetch github.com/hashicorp/hil/... 2017-05-04 15:56:35 -07:00
evaltype_string.go vendor: update HIL 2016-11-13 10:28:26 -08:00
go.mod vendor: github.com/hashicorp/hil@latest 2019-02-12 15:56:22 +00:00
go.sum vendor: github.com/hashicorp/hil@latest 2019-02-12 15:56:22 +00:00
LICENSE deps: Update github.com/hashicorp/hil/... 2016-04-18 16:31:19 -07:00
parse.go vendor: update HIL 2016-11-13 10:28:26 -08:00
README.md deps: Update github.com/hashicorp/hil/... 2016-04-18 16:31:19 -07:00
transform_fixed.go deps: Update github.com/hashicorp/hil/... 2016-04-18 16:31:19 -07:00
walk.go vendor hashicorp/hil 2016-02-03 13:24:04 -05:00

HIL

GoDoc Build Status

HIL (HashiCorp Interpolation Language) is a lightweight embedded language used primarily for configuration interpolation. The goal of HIL is to make a simple language for interpolations in the various configurations of HashiCorp tools.

HIL is built to interpolate any string, but is in use by HashiCorp primarily with HCL. HCL is not required in any way for use with HIL.

HIL isn't meant to be a general purpose language. It was built for basic configuration interpolations. Therefore, you can't currently write functions, have conditionals, set intermediary variables, etc. within HIL itself. It is possible some of these may be added later but the right use case must exist.

Why?

Many of our tools have support for something similar to templates, but within the configuration itself. The most prominent requirement was in Terraform where we wanted the configuration to be able to reference values from elsewhere in the configuration. Example:

foo = "hi ${var.world}"

We originally used a full templating language for this, but found it was too heavy weight. Additionally, many full languages required bindings to C (and thus the usage of cgo) which we try to avoid to make cross-compilation easier. We then moved to very basic regular expression based string replacement, but found the need for basic arithmetic and function calls resulting in overly complex regular expressions.

Ultimately, we wrote our own mini-language within Terraform itself. As we built other projects such as Nomad and Otto, the need for basic interpolations arose again.

Thus HIL was born. It is extracted from Terraform, cleaned up, and better tested for general purpose use.

Syntax

For a complete grammar, please see the parser itself. A high-level overview of the syntax and grammer is listed here.

Code begins within ${ and }. Outside of this, text is treated literally. For example, foo is a valid HIL program that is just the string "foo", but foo ${bar} is an HIL program that is the string "foo " concatened with the value of bar. For the remainder of the syntax docs, we'll assume you're within ${}.

  • Identifiers are any text in the format of [a-zA-Z0-9-.]. Example identifiers: foo, var.foo, foo-bar.

  • Strings are double quoted and can contain any UTF-8 characters. Example: "Hello, World"

  • Numbers are assumed to be base 10. If you prefix a number with 0x, it is treated as a hexadecimal. If it is prefixed with 0, it is treated as an octal. Numbers can be in scientific notation: "1e10".

  • Unary - can be used for negative numbers. Example: -10 or -0.2

  • Boolean values: true, false

  • The following arithmetic operations are allowed: +, -, *, /, %.

  • Function calls are in the form of name(arg1, arg2, ...). Example: add(1, 5). Arguments can be any valid HIL expression, example: add(1, var.foo) or even nested function calls: add(1, get("some value")).

  • Within strings, further interpolations can be opened with ${}. Example: "Hello ${nested}". A full example including the original ${} (remember this list assumes were inside of one already) could be: foo ${func("hello ${var.foo}")}.

Language Changes

We've used this mini-language in Terraform for years. For backwards compatibility reasons, we're unlikely to make an incompatible change to the language but we're not currently making that promise, either.

The internal API of this project may very well change as we evolve it to work with more of our projects. We recommend using some sort of dependency management solution with this package.

Future Changes

The following changes are already planned to be made at some point:

  • Richer types: lists, maps, etc.

  • Convert to a more standard Go parser structure similar to HCL. This will improve our error messaging as well as allow us to have automatic formatting.

  • Allow interpolations to result in more types than just a string. While within the interpolation basic types are honored, the result is always a string.