Let's think about this for a second
HCL syntax is designed to be more readable than JSON/YAML — you'll see the pattern `block_type "label" { argument = value }` over and over. Block types (resource, provider, variable, output) are Terraform's 'keywords.' An argument follows the `key = value` pattern — the value can be a string, number, boolean, list, or map. An expression is how you reference another resource's output using `${...}` syntax (which you can omit in modern HCL) to connect values together.
Let's connect this to a real scenario
Code like `resource "local_file" "greeting" { filename = "hello.txt"; content = "Hello, Terraform!" }` reads as: 'a resource of type local_file, named greeting in my config, with two arguments — filename and content.' You write comments with `#` (or `//`), and multi-line strings with heredoc syntax (`<<EOF ... EOF`).
Let's look at an example
# This is a comment
resource "local_file" "greeting" {
filename = "hello.txt"
content = "Hello, Terraform!"
}
variable "environment" {
type = string
default = "dev"
}
locals {
tags = {
project = "tutorial"
owner = "student"
}
}Be able to read HCL block/argument/expression syntax.5-minute try-it
Read the HCL code above and write out, for each of the 3 block types (resource, variable, locals), what its label and arguments are.
A quick word of caution
HCL files use the `.tf` extension — Terraform loads every `.tf` file in a folder together as one combined configuration, not as separate individually-run files.