You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
HashiCorp Configuration Language (HCL) is the language used to write Terraform configuration files. This lesson covers HCL syntax, block structure, arguments, expressions, functions, and comments.
HCL files use the .tf extension. The language is designed to be:
HCL is built around blocks. Every block has a type, optional labels, and a body:
block_type "label_1" "label_2" {
argument = value
}
| Block Type | Labels | Purpose |
|---|---|---|
terraform | none | Terraform settings (providers, backend) |
provider | provider name | Provider configuration |
resource | type, name | Infrastructure resource |
data | type, name | Data source (read-only) |
variable | name | Input variable |
output | name | Output value |
locals | none | Local values |
module | name | Module call |
Arguments assign values inside blocks:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0" # string
instance_type = "t3.micro" # string
count = 2 # number
monitoring = true # boolean
}
Attributes are values exposed by a resource after creation (e.g., aws_instance.web.id).
| Type | Example | Description |
|---|---|---|
| string | "hello" | Text |
| number | 42, 3.14 | Integer or float |
| bool | true, false | Boolean |
| list | ["a", "b", "c"] | Ordered collection |
| set | toset(["a", "b"]) | Unordered unique collection |
| map | { key = "value" } | Key-value pairs |
| object | { name = string, age = number } | Typed key-value pairs |
| tuple | [string, number] | Typed ordered collection |
| null | null | Absence of a value |
Use ${ } for interpolation within strings:
resource "aws_instance" "web" {
tags = {
Name = "web-${var.environment}"
}
}
For multi-line strings:
resource "aws_iam_policy" "example" {
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "*"
}]
}
EOF
}
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.