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?
Automation: No need to manually configure resources.
Consistency: The same code can be reused to deploy environments.
Version Control: Store configurations in Git to track changes.
Multi-Cloud Support: Works with AWS, Azure, Google Cloud, and more.
STEPS TO INSTALL,CONFIGURE AND USE TERRAFORM
- First step is to install Terraform on our local environment (Linux) to do that we click the link https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli Then we click on Linux and we copy the first code and paste on our environment terminal.
- 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?
Efficiency: Quickly perform tasks without navigating through a web interface.
Automation: Easily script and automate repetitive tasks.
Cross-Platform: Works on Windows, macOS, and Linux.
Getting Started
- Install Azure CLI: Follow the installation guide for your operating system, for this we are using LINUX operating System https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt copy the code and paste in ur local environment
- 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
Initialize: terraform init
Plan: terraform plan
Apply: terraform apply
- We are going to create a directory using
mkdir (name of the directory)
andCD (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 theterraform plan
.
You will be asked to confirm by typing Yes
For confirmation head to your azure to confirm that u have successfully created a resource group
Top comments (0)