gitmyhub

hcl

Go ★ 5.8k updated 1d ago

HCL is the HashiCorp configuration language.

HCL is a configuration language created by HashiCorp, the company behind tools like Terraform and Vault. Its purpose is to give developers a clean, readable way to write configuration files for their tools, sitting somewhere between the simplicity of JSON or YAML and the full power of a programming language.

The language has two forms that represent the same underlying data. The native syntax is designed to be written and read by people: it uses blocks, labels, and key-value pairs in a way that is more concise and expressive than JSON. The JSON form is designed for machine-generated configuration, and the two can be mixed freely since they map to the same internal structure. That means a tool can accept both hand-written HCL files and machine-generated JSON files and process them identically.

HCL supports expressions inside configuration values, not just static strings or numbers. You can do arithmetic, use string interpolation to embed variable values, and call functions defined by the application. This lets configuration files express conditional or computed settings without becoming full programs. The application developer defines which variables and functions are available, so the scope of what configuration authors can do is controlled.

The library is intended for Go developers who want to build their own tools with a structured configuration format. Rather than designing a format from scratch or accepting raw JSON, they use HCL to get built-in parsing, validation, and error messages. The application declares what structure it expects, and HCL checks that the configuration file matches and returns the parsed values.

This is version 2, which has an incompatible API with version 1. HCL originated in HashiCorp's Terraform project and was later extracted into a standalone library. It is released as open source under the Mozilla Public License.