Skip to main content

Command Palette

Search for a command to run...

Terraform and Terraform Basics

Published
3 min read
Terraform and Terraform Basics

What is Terraform?

Terraform is an infrastructure as a code tool that lets you build, change and version cloud and on-premise resources safely and efficiently.

What is Infrastructure as a code?

Provisioning infrastructure using scripts/tools instead of manually configuring machines.
Where, Provisioning Means:- Creating, Updating, Deleting

Terraform

Terraform is HashiCorp's infrastructure as a code tool. It lets you define resources and infrastructure in human-readable, declarative configuration files and manages your infrastructure's lifecycle. Using Terraform has several advantages over manually managing your infrastructure

  • Terraform can manage infrastructure on multiple cloud platforms.

  • Terraform's state allows you to track resource changes throughout your deployments.

  • You can commit your configurations to version control to safely collaborate on infrastructure.

  • The human-readable configuration language helps you write infrastructure code quickly.

Install Terraform on windows:

  1. https://www.terraform.io

  2. Download Terraform software.

  3. Extract the downloaded zip file.

  4. Add Terraform path to system environment variables.

  5. Command:- terraform --version

    terraform --help

Step 1:- Go to the Download option

Step 2:- Click on Windows and download AMD64 version.

Step 3:- Create one Terraform folder in C Drive and extract the downloaded zip file

Step 4:- Check on the windows command prompt if it is working or not.

Please check properly in the above command prompt that the path is
"c:\terraform\terraform_1.4.2_windows_amd64"

Now I want to run commands present in other than above path. I am getting some errors. Please check below.

In this time you have set system environment variables. You can run commads from any location.

Go to system environment variables and then click on PATH and edit it.

Save the above path in edit environment variables. Now your system environment variables process is done successfully.

Now you are able to run commands from any location.

--------------------------------------------------------------------------

Install Terraform on Linux OS:

Package manager for Linux

$ wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
$ echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
$ sudo apt update && sudo apt install terraform

------------------------------------------------------------------------------------------

Familiarize yourself with HCL syntax used in Terraform

HCL syntax has 3 parts-
1. Blocks:- Block group expression, arguments and other blocks into a labeled structure.
2. Arguments:- It is like a Key:Value pair.
3. Expression:- Expression either represent or compute values.
Numeric Expression
Boolean Expression
Arithmetic Expression

Example:

**Understand variables**

  • Input Variables: serve as parameters for a Terraform module, so users can customize behavior without editing the source.

  • Output Values: are like return values for a Terraform module.

Now create your first Linux Operating system using Terraform:

Resource block describes one or more infrastructure objects associated with the providers.
Examples1:-
resource aws_instance
resource aws_alb
resource iam_user
resource digitalocean_droplet

Example2:-

Now if you want t create a Git repository with the help of Terraform use the below file.
Go to the Terraform registry --> Provider --> Integration --> Github --> Documentation

More from this blog

Nilesh Ganvir

34 posts