Terraform uses Hashi Corp configuration language (HCL) for writing scripts. In this guide, we’ll explore the basic building blocks of Terraform and its life cycle. Instead of being a programming language, HCL serves as a descriptive language that describes your infrastructure in simple terms. Furthermore, it’s a lot simpler than HTML but delivers a powerful impact in creating infrastructure.

Block
First, let’s understand the basic building block in Terraform – the “Block”. Notably, the syntax remains very simple and easily understandable as it follows a clear pattern
<BLOCK_TYPE> <ARGUMENTS>{
key1=value1
key2=value2
}
The block type describes what type of block it is ,there are around 7 block types.
The arguments vary in count based on the types
The body of the block contains key value pair that sets the values related to the block . For instance we are creating a s3 bucket it will contain key value pairs related to s3 bucket. We will understand it with an example to make things clear.
Hello World Example
We will create a text file in our local machine with content as hello world. This is very simple example, without incurring costs. Even though this doesn’t look much it can help us to understand the whole workflow .
Let us create hello.tf , we can make use of the vscode IDE to run and edit terraform scripts.

resource "local_file" "hello"{
filename = "hello_world.txt"
content = "Hello, World! from terraform"
}
- resource – indicates that it is going to create a “Resource”
- “local_file” – The first part before the underscore represents the provider, while the second half specifies the resource type within that provider
- hello – It is name of the block with in the context of terraform.
Execution Steps
Before we execute any script with respect to terrafrom , we need to run “Terraform init”. This will initialize the providers , download the plugins required for running the script. Remember , terraform uses plugin architecture.
terraform init

If you read the output closely there are many things happening after executing a simple
- Initializing the backend
- Initializing provider plugin
- Finding latest version of Hashicorp/local
- Installing the hashicorp/local
- Terraform has created a lock file .terrafrom.lock.hcl to record provider section it made above
Ultimately, we’ll learn everything mentioned above. For now, let’s focus on the Local plugin that hashicorp/local publishes. Moreover, terraform creates all these files in your local folder

We see an exe file is in place
Terraform.lock.hcl
This file keeps track of the plugins and their headers
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/local" {
version = "2.6.2"
hashes = [
"h1:L2Fh/vCr+A2yeN6mdUcXx6ZNLW68LFGkfQ+Lx/edFHY=",
"zh:018382c416d271bf89be6fba6550b4fae42e31a4d26a421b3c92f1d589b1b086",
"zh:107fd03879eb10d26dcaf5a68d98e4ca7d2488e43c01868e27698d248c1f42a2",
"zh:4854946830189100e6a36b8facf028244a7a54baf6e9f5a1a68d11669d8ee597",
"zh:4a23aee49842043cb3305f62fa04c3231eb5e6250a439b9a895d8c928a4408a3",
"zh:5becec4296cd32ac2b75198ed2de9f716a4c2094ee59d85244d589ae025dfdb6",
"zh:619822fb681d7d44c13c1d5ca3d5c85978a8dc8bca18f21bcb80e71816c3f6cd",
"zh:6f781cdfde321d530d9b0e4b03ee92a3ec16c82951ab22346ef647d84db321a1",
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
"zh:8418a84aeed1b31796ffb8c61749406b25e764a4f5a53de29b7ba7c2619692e3",
"zh:ab28bd1283712a9720a40c50cc85baffce0f2c23266144602ebbbf1a6a2bccda",
"zh:b848cae1d5d1103ba47bd650f27802f316f7bc0dc54df82c514d74269bfcdca5",
"zh:bd467d695311c19eec13712792934c19e1b33f351e0cc1fffa08ce404b7d503d",
]
}
Additionally, you can run this command multiple times to pull the required dependencies whenever needed
Terraform Plan
This is the first step you need to execute after the plan , terrafrom plan. Which will create action plan on how to create the resource
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
+ create
Terraform will perform the following actions:
# local_file.hello will be created
+ resource "local_file" "hello" {
+ content = "Hello, World! from terraform"
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "hello_world.txt"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run
"terraform apply" now.
Terraform Apply
terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
+ create
Terraform will perform the following actions:
# local_file.hello will be created
+ resource "local_file" "hello" {
+ content = "Hello, World! from terraform"
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "hello_world.txt"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
local_file.hello: Creating...
local_file.hello: Creation complete after 0s [id=e33ed416e8e92e3236c0e0b118a9048bd2ceacb9]
This has created the file now.

Along with the file we will also get a state file which keeps track of infrastructure .
Terraform State
The terraform state file is single source of truth.
{
"version": 4,
"terraform_version": "1.14.4",
"serial": 1,
"lineage": "cda0d5cf-aae1-6303-5f6b-fe99df661995",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "local_file",
"name": "hello",
"provider": "provider[\"registry.terraform.io/hashicorp/local\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"content": "Hello, World! from terraform",
"content_base64": null,
"content_base64sha256": "bp3BL2g5ZICdopKAIntV3tbR/jPf8ekRZW/oj0rawlU=",
"content_base64sha512": "aBLntVZNO88EgPQIf4ht4KTD9TdK5KbjzXS1UwjWjyjbVYratNMo5OXfj3EYrqJgqZrbQaeeo+z+b3AilD/62g==",
"content_md5": "34234f75d7cebd521da015b2210fc36d",
"content_sha1": "e33ed416e8e92e3236c0e0b118a9048bd2ceacb9",
"content_sha256": "6e9dc12f683964809da29280227b55ded6d1fe33dff1e911656fe88f4adac255",
"content_sha512": "6812e7b5564d3bcf0480f4087f886de0a4c3f5374ae4a6e3cd74b55308d68f28db558adab4d328e4e5df8f7118aea260a99adb41a79ea3ecfe6f7022943ffada",
"directory_permission": "0777",
"file_permission": "0777",
"filename": "hello_world.txt",
"id": "e33ed416e8e92e3236c0e0b118a9048bd2ceacb9",
"sensitive_content": null,
"source": null
},
"sensitive_attributes": [
[
{
"type": "get_attr",
"value": "sensitive_content"
}
]
],
"identity_schema_version": 0
}
]
}
],
"check_results": null
}
Summary:
- Write the tf script
- terraform init and validate the plugin
- terraform plan and validate the addition
- run terraform apply to create resources
- Finally, run terraform destroy to remove all resources when you’re done




[…] uses providers to talk with different clouds, they are plugins to that particular cloud plugins. In our previous example we have used provider local, this provider is created by HashiCorp. There are three tiers of […]