Sunday, 10 December 2023

Create resource on Azure with Terraform

What is Terraform?

Terraform is an Infrastructure as Code (IaC) software tool offered by HashiCorp. You can provision and manage your infrastructure both on-premises and in the cloud with it. 


How to execute Terraform Scripts?


Prerequisite

1. You need an Azure Portal account
2. Install Azure CLI on your local system. Download the installer from the below link
    Azure CLI Installer
3. Azure Login on command prompt run (az login) command 
4. Install Terraform. Download the installer from the below link. Download 
AMD64 for     64-bit system. Terraform Download

 

Let's create a small script to create a resource Group in the Azure portal.


Step 1: Create a Terraform file to create a resource group. Paste the below script into the new file and the name should be anyname.tf

provider "azurerm" {
  version = "~>2.0"
  features {}
}

resource "azurerm_resource_group" "terraform1" {
  name = "terraform1"
  location = "eastus"
}

Place the file in any drive. I have placed the file in the D drive. Below is my file. My Resource group name is terraform1. You can write any name.











Step 2: Intialize Terraform.


My file is on D drive. So I have executed the command from D drive.
            terraform init










Step 3: Terraform Plan

            Execute command    terraform plan













Step 4: Terraform Apply

            Execute command    terraform apply












It will prompt you to perform this action? Write Yes and Enter.








After yes, it will start creating the infrastructure on the Azure Portal










You can see the success message above. Go to the Azure portal, and you can see a new resource group with the name terraform1.
















That's all about this article. 


No comments:

Post a Comment

Implement Authorization in Swagger with Static Value in Header .Net 8

If you want an anonymous user should not run the APIs. To run your API Endpoints From Swagger / Postman / Code the user should pass the head...