Introduction

Learn about the HCL and its major components.

Overview

The first step required for provisioning infrastructure using Terraform is to define the infrastructure in a series of configuration files. Writing configuration files for Terraform can be achieved using either of the two formats below:

  • JSON
  • HCL

JSON

We can write Terraform configuration files using JSON, however, the syntax can be quite complex and cumbersome. Configuration files defined in the JSON format usually have the file extension .tf.json. A sample configuration written in JSON format is given below.

Press + to interact
{
"resource": {
"aws_instance": {
"sample_instance": {
"instance_type": "t2.micro",
"ami": "ami-0a606d8395a538502"
}
}
}
}

HCL

HCL is a language that was developed by HarshiCorp to make the writing of configuration files easy and improve readability. Configuration files that are written in HCL end with the file extension .tf. HCL is a lot more flexible than the regular JSON format. A sample ...