Back to course

Understanding HCL Syntax

Infrastructure as Code (Terraform & OpenTofu Mastery)

HCL: HashiCorp Configuration Language

IaC is written in HCL. It is designed to be human-readable and machine-friendly. It looks like a mix between JSON and YAML but is much more powerful.

Anatomy of a Block

hcl resource "aws_instance" "web_server" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro"

tags = { Name = "MyFirstServer" } }

  • Block Type: resource (what are we making?)
  • Resource Type: aws_instance (which specific cloud object?)
  • Local Name: web_server (how do we refer to it in our code?)
  • Arguments: ami, instance_type (the settings).