HCL
By HashiCorp
HCL (HashiCorp Configuration Language) is a structured configuration language designed by HashiCorp to be both human-readable and machine-friendly, used primarily to define infrastructure resources in Terraform. It combines a…
Definition
HCL (HashiCorp Configuration Language) is a structured configuration language designed by HashiCorp to be both human-readable and machine-friendly, used primarily to define infrastructure resources in Terraform. It combines a JSON-compatible structure with a more readable block syntax, expressions, and variables, letting teams declare cloud resources, providers, and dependencies as code. HCL is also used in other HashiCorp tools such as Vault, Consul, and Packer for their own configuration needs.
Overview
HCL was created by HashiCorp to address a gap between raw JSON, which is easy for machines to parse but awkward for humans to write and comment on, and full programming languages, which offer expressiveness but more complexity than most infrastructure configuration needs. HCL aims to sit between the two: structured and unambiguous enough for tooling, but readable enough for engineers to write and review infrastructure definitions directly. Mechanically, HCL organizes configuration into named blocks, such as `resource`, `provider`, or `variable`, each containing key-value arguments and optionally nested blocks. Terraform's execution model reads these blocks to build a dependency graph between resources, resolving references between them, such as one resource's ID being passed as an input to another, and HCL supports interpolation expressions, conditionals, and loops through `for_each` and `count` constructs to avoid duplicating near-identical resource declarations. HCL differs from Jsonnet in scope and intent: Jsonnet is a general-purpose data templating language usable for any JSON-shaped output, while HCL is purpose-built around infrastructure and tool configuration with built-in semantics for resources, providers, and modules specific to Terraform and other HashiCorp products. It also differs from YAML, the format used by Kubernetes and many CI/CD tools, in supporting native expressions and interpolation directly in the language rather than relying on a separate templating layer. In practice, HCL is best known as Terraform's configuration language, where it defines cloud infrastructure resources across providers like AWS, Azure, and Google Cloud, along with the variables, outputs, and modules used to structure larger deployments. HashiCorp also uses HCL for configuring Vault policies, Consul service definitions, and Packer image-building templates, giving teams a consistent syntax across the HashiCorp product ecosystem even though each tool interprets its own block schema differently. HCL's expressiveness is intentionally constrained compared to a general-purpose language, which keeps configuration declarative and predictable but can feel limiting for complex conditional logic that a real programming language would handle more naturally, pushing some teams toward code-generation workarounds. Being closely tied to the HashiCorp ecosystem, it also has less use outside those tools compared to more universal formats like YAML or JSON. Teams use HCL specifically when working within Terraform or another HashiCorp tool, and use JSON or YAML with a general-purpose language when configuration logic grows too complex for HCL's declarative constructs. Community-maintained providers and modules published for Terraform are all written in HCL, so practical fluency in the language is effectively required for anyone maintaining or extending infrastructure code built on the Terraform ecosystem.
Key Features
- Block-based syntax for resources, providers, variables, and modules
- JSON-compatible underlying structure usable as an alternative syntax
- Native expressions, interpolation, and conditional logic
- Loop constructs like `for_each` and `count` to avoid duplication
- Primary configuration language for Terraform infrastructure as code
- Also used in Vault, Consul, and Packer configuration
- Builds a resource dependency graph from block references
- Designed to balance human readability with machine parseability