0
0
TerraformConceptBeginner · 3 min read

What is HCL in Terraform: Simple Explanation and Example

HCL stands for HashiCorp Configuration Language, a simple and human-friendly language used to write Terraform configuration files. It helps you describe your cloud infrastructure in a clear, readable way that Terraform can understand and apply.
⚙️

How It Works

Think of HCL as a recipe book for your cloud setup. Instead of cooking food, you write down instructions for creating servers, networks, and other resources. Terraform reads this recipe and follows it to build your infrastructure exactly as you described.

HCL uses a clean and easy-to-read format with blocks and key-value pairs, making it simple for humans to write and understand. It’s designed to be both machine-friendly and user-friendly, so you don’t need to be a programmer to use it.

💻

Example

This example shows a basic Terraform configuration written in HCL that creates a simple AWS EC2 instance.

hcl
provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}
Output
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
🎯

When to Use

Use HCL whenever you want to manage cloud infrastructure with Terraform. It is perfect for defining resources like servers, databases, and networks in a clear way. HCL is especially helpful when you want to keep your infrastructure code easy to read, share, and maintain.

Real-world uses include setting up cloud environments for websites, apps, or data storage, automating infrastructure changes, and managing resources across multiple cloud providers.

Key Points

  • HCL is a simple language designed for writing Terraform configurations.
  • It uses blocks and key-value pairs to describe infrastructure resources.
  • HCL is easy for humans to read and write, making infrastructure management clearer.
  • Terraform uses HCL files to create, update, and delete cloud resources automatically.

Key Takeaways

HCL is the language Terraform uses to describe cloud infrastructure clearly and simply.
It uses a readable format with blocks and key-value pairs for easy writing and understanding.
Terraform reads HCL files to automate building and managing cloud resources.
Use HCL to keep your infrastructure code organized, shareable, and maintainable.