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 –
- At first, we need to initialize the backend by running “terraform init”
- Next, we can run “terraform plan” to see the plan, it will show what changes will be done.
- 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.
- Kubernetes Series: Part 1 – Introduction to Kubernetes | Background of Kubernetes
- Kubernetes Series: Part 2 – Components of Kubernetes cluster | Kubernetes cluster in detail
- Kubernetes Series: Part 3 – What is Minikube and How to create a Kubernetes cluster (on Linux) using Minikube?
- Introduction to Ansible | High Level Understanding of Ansible
- Basics of automation using Ansible | Automate any task
- Automation of Java installation – using Ansible
- Automation of JBoss EAP installation – using ansible
- Jenkins Pipeline as code – High level information
- Jenkins pipeline script to build Java application and push artifacts into repository
- Jenkins pipeline script to build & deploy application on web server
- What is End-to-End Monitoring of any web application, and Why do we need it?
- What is “Monitoring” in DevOps? Why do we need to Monitor App/DB servers, Transactions etc.?
- DevOps Engineer or Software Developer Engineer which is better for you?- Let’s discuss
- How To Be A Good DevOps Engineer?
- How to do git push, git pull, git add, git commit etc. with Bitbucket