HCL Syntax
Source: doonops-curriculum/hcl-core--hcl-syntax.md
Doonops lesson
Goal
Read and write basic HCL blocks without fear.
Simple explanation
HCL is not Python. It is a list of labeled boxes: resource "type" "name" { settings inside }.
Technical view
Blocks: resource, data, variable, output, module, provider. Attributes key = value; types string, number, bool, list, map.
Think of it like
Filling a government form: section title (resource), your name (resource name), fields inside { }.
Steps
- Read simple section
- Read analogy + diagram
- Copy project files
- Do local lab
Deep explanation
Layman words first, then technical detail — read slowly
One resource — explained like a form
resource "aws_instance" "doonops_app" {
│ │ │
│ │ └── your nickname for this server (only in Terraform)
│ └── AWS product type (EC2 instance)
└── keyword: we are CREATING something
ami = "ami-xxx" ← which OS image (like Windows vs Linux DVD)
instance_type = "t3.micro" ← size (small / medium machine)
tags = { Name = "doonops-app" } ← labels for humans
}
Data types (simple)
- String — text in quotes:
"ap-south-1" - Number — no quotes:
3 - List — [ ] multiple values: subnets list
- Map — { } key-value tags
Terraform HCL mein Python jaisa for i in range() loop resource block ke andar usually nahi likhte — uske liye count / for_each use hota hai (next modules).
Example (Doonops)
Modern HCL — names are examples, not from any third-party course
resource "aws_instance" "doonops_app" {
ami = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
tags = { Name = "doonops-app" }
}Terraform runs on your computer — copy this HCL into a folder, then follow the local lab steps below.
Check
- What does resource "aws_instance" "app" mean?
- String vs number example
Project files for this lab
Full implementation folder — copy all files, then run terraform commands
Lab project files (full folder)
Copy every file below into one folder — same as a real repo module. Then run the local lab steps.
Suggested folder: Suggested path: ~/doonops-terraform/04-hcl-ec2/
versions.tfSee file purpose in the code belowterraform {
required_version = ">= 1.9.0"
}