HashiCorp Configuration Language is designed by HashiCorp to build a configuration language that is friendly for both machines as well as human. It is mainly for command-line tools and targeted for servers and DevOps tools. Besides, it is JSON compatible which means one can use JSON can be used as a valid input. This is what makes HashiCorp Configuration Language interoperable with various other systems. Currently, it is being used in HashiCorp’s cloud infrastructure automatic tools. It is a direct competition to the well-known configuration languages such as YAML and even JSON to some extent. In comparison to them, HCL is easy to read and write, and it is well-structured.
The Rise Of HashiCorp Configuration Language –
Prior to HashiCorp Configuration Language, HashiCorp used various configuration languages which ranged from full-fledged programming languages like Ruby to data structure languages like JSON. However, it was clear from the community discussions that programmers wanted a more programmer-friendly configuration language that is also machine-friendly.
Apparently, JSON was a perfect fit in these parameters. However, there are a lot of drawbacks like the absence of commenting option. As far as YAML goes, the beginners had a huge trouble in determining the actual structure. They have to depend on guesswork when to use hyphen and color and likewise. Coming to Ruby, it has a steep learning curve which made it not so suitable as a configuration language.
Therefore, the lack of an ideal configuration language forced the company to come up with their own configuration language. However, it is made JSON-compatible because out of YAML, Ruby, and JSON, JSON was the most preferred. The language is designed to be modified as per requirement and hence, user-friendly. There are APIs for JSON to be taken as an input and hence, machine-friendly. We all know that machines can generate JSON directly. Besides, JSON is responsible for the interoperability layer.
Key Elements Of HCL –
It has single line comment, multi-line comment, and nested block comments. Values are assigned with key=value syntax. The value can be anything from a string and a number to an object and a list. Strings can have any UTF-8 characters with double quotes. As a matter of fact, multi-line strings are also allowed. The numbers by default have base 10. However, if you start with 0x, it will be treated as hexadecimal. There are Booleans as well along with arrays.
Interestingly, arrays can have primitives, objects as well as other arrays. HCL syntaxes are made out of blocks or stanzas. Two other interesting inclusions are maps and interpolated variable reference and interpolations syntax. HCL uses a set of constructs that can be used by the calling applications. As of now, HCL is mostly used in applications written in GO language.
Conclusion –
HashiCorp Configuration Language (HCL) is one of the rising stars of GitHub in 2018 along with TypeScript and Kotlin. It has the largest growth as far as contributors are concerned contributing to the code repositories. It is widely used for setting up software libraries, application dependencies, and development environments. It has already become popular among DevOps engineer, and the popularity is only going to explode this year.