What is Terraform?
Terraform is a tool that helps you create and manage cloud resources like virtual machines, networks, databases, and more using code. Instead of manually clicking through a cloud provider's interface, you write a file describing what you want,and Terraform makes it happen.

Why Use Terraform?

  1. Automation: No need to manually configure resources.
  2. Consistency: The same code can be reused to deploy environments.
  3. Version Control: Store configurations in Git to track changes.
  4. Multi-Cloud Support: Works with AWS, Azure, Google Cloud, and more.

STEPS TO INSTALL,CONFIGURE AND USE TERRAFORM

  • Move to the next code, copy and paste in your environment.

  • Copy the next code also and do the same.

  • Do the same also for the next code.

  • Copy the next two code simultaneously and paste on your terminal in your local environment.

  • Next we need to verify that we have successfully installed terraform we type terraform -help

What is AZURE CLI

Azure Command-Line Interface is a tool u can use to manage Azure Resources directly from your command line. It is a way to communicate with Azure using text commands instead of clicking around in a web portal.

Why Use Azure CLI?

  1. Efficiency: Quickly perform tasks without navigating through a web interface.
  2. Automation: Easily script and automate repetitive tasks.
  3. Cross-Platform: Works on Windows, macOS, and Linux.

Getting Started

  • To Prove that it worked we type the code az login then u will get a url at the end of the page to redirect you to your azure login page

  • After successfully logging into your Azure account from the URL provided you should get this popping up.

  • You choose your current subscription if you have multiple.

  • Next we are going to create a RG (resource group), using the command az create --name (rg name) --location (Preferred location)

If u check your azure account, you will see that u have a created a resource group and location.

CREATING A TERRAFORM / Running Terraform

  1. Initialize: terraform init
  2. Plan: terraform plan
  3. Apply: terraform apply
  • We are going to create a directory using mkdir (name of the directory) and CD (name of the directory) into the directory.

  • Next we create a terraform file using our text editor VIM to create and edit the file i am going to name it main.tf

Note: TOUCH command only creates the file, But VIM allows use to create and edit the text file press I to be in insert mode to be able to type in our text file

  • Next we generate a main.tf file that will deploy a resource group to azure in our text file making sure your azure subscription is added. To save this and exit our text editor we hit Shift column wq

  • Next we hit the code terraform init this will initialize a working directory containing. It is the first command you run when you start working with Terraform.

  • Next we need to hit terraform plan this helps you preview the changes Terraform will make to your infrastructure before actually applying them.

  • Terraform Apply is the next code will implement the terraform plan.

You will be asked to confirm by typing Yes

Read full article