Introduction to terraform - high level information

Introduction to terraform – high level information

Last Updated on February 18, 2023 by cscontents

Introduction

Terraform is an open source tool which is used to write “infrastructure as code”. That is, we can use terraform to write code which will manage infrastructure.

In this article we will see some high level information.

Which language is used by terraform?

There are two language –

  • HCL (HashiCorp Configuration Language) – The language which is used to write the terraform files (.tf). We need to learn this to use terraform.
  • GO language – core part of terraform is written in GO language.

Where terraform is used?

Terraform is used to manage infrastructure on cloud platforms (majorly) as well as for on-premise infrastructure.

Terraform supports almost all major cloud provider (e.g., Microsoft Azure, AWS, GCP etc.) where we can use terraform to manage (provision, deletion, modification) infrastructure.

How to use terraform?

To use terraform we need to follow below steps.

Step 1 – Install terraform

we need to install it on our machine. Depending on our OS we can go through the various steps to install it. Below is the link of documentation to install terraform:

https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli#install-terraform

Once it is installed we can verify it by running the below command to check its version.

terraform -v

Step 2 – Give access to terraform

Terraform should have access to cloud platform so that it can manage the infrastructure. So we should give access to terraform

Step 3 – Create terraform files

If you are new to terraform, then you can start with creating a “main.tf” file where you can declare the cloud provider details (otherwise you can also create separate .tf file for provider) and resource details which you want to create.

Few basic points you need to remember while writing terraform files –

  • Terraform treats everything as a “resource”, that is every component of infrastructure is assumed to be a resource.
  • When we write code for any resource, it has two names
    • One is its actual name which we will see on the cloud portal after provisioning.
    • Another name is used by terraform. This name is used when we are calling any resource within the .tf files.

Step 4 – Run terraform commands

Once we have the required .tf files, we need to run the terraform commands. Below are the basic flow of commands –

  1. At first, we need to initialize the backend by running “terraform init”
  2. Next, we can run “terraform plan” to see the plan, it will show what changes will be done.
  3. Next, we need to run “terraform apply” to provision the resources.

These are main commands when we are provisioning any resource. There are other commands which are used to destroy and modify resources. We will discuss them later.

This is all for now.

 

Thanks

 

If you are interested in learning DevOps, please have a look at the below articles, which will help you greatly.