Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
HashiCorp Configuration Language  ›  Lesson

What Is HCL?

What is HCL? 12 minHCL is HashiCorp's configuration language: a readable, declarative format of blocks and arguments, stored in .tf files that Terraform loads together as one configuration.

What Is HCL?

Open any Terraform project and you will see files ending in .tf. They are not JSON, not YAML and not a programming language, though they borrow a little from each. They are written in HCL, and you will read it every day.

The rule

HCL is blocks of settings; every .tf file in a folder is one configuration.

HCL (HashiCorp Configuration Language) was designed to be easy for people to read and write while still being precise enough for a tool. It is declarative: you describe things, you do not write step-by-step instructions.

Here is the start of Crumb's configuration:

# Crumb bakery: storage for cake photos
resource "aws_s3_bucket" "assets" {
  bucket = "crumb-bakery-assets"

  tags = {
    team = "web"
  }
}

Things to notice:

  • Blocks wrap related settings in { }.
  • Arguments are name = value lines.
  • Comments start with # (also //, and /* ... */ for several lines).
  • Values can be strings, numbers, true/false, lists [...] and maps {...}.

Terraform reads every .tf file in the current folder (not sub-folders) and treats them as one configuration. The order of blocks and files does not matter. The usual split is purely for people:

  • main.tf — resources
  • variables.tf — inputs
  • outputs.tf — results
  • providers.tf or versions.tf — provider settings

There is also a JSON form, .tf.json, meant for files that programs generate. People write .tf.

Whitespace is flexible: indentation and blank lines are for readers, and terraform fmt rewrites files into the standard layout, so teams never need to argue about spacing.

The shortcut

When you open an unfamiliar project, read it as nouns, not steps. Each block is a thing that should exist; the file it lives in and its position are irrelevant.

Reading Crumb's folder for the first timeStep 1 of 4
  1. List the files

    main.tf, variables.tf, outputs.tf. Terraform merges them into one configuration.

The trap: putting a .tf file in a sub-folder and expecting it to load. Sub-folders are separate modules, not part of this configuration.

Drills

Answer fast — trust the rule.

quick drill

Which files does Terraform load from the working folder?

quick drill

What is HCL's style?

quick drill

You move a resource block from the top of main.tf into a new file storage.tf in the same folder. What changes in the plan?

quick drill

Which line is a valid HCL comment?

Remember

  • HCL is declarative: blocks of name = value settings.
  • Shortcut: read blocks as nouns; file names and order do not matter.
  • Trap: .tf files in sub-folders are not loaded as part of this configuration.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhy a special language?

A teammate asks why Terraform uses HCL instead of plain JSON or a general programming language, and whether it matters that Crumb's configuration is split into main.tf, variables.tf and outputs.tf. Answer both questions.