How to User Terraform code to create Azure resource (Part -8)

Simple examples to create resource group

Create Azurerm provider

terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.105.0"
    }
  }
}

provider "azurerm" {
  # Configuration options
}

Under configuration option

Use below available options:

Azure Provider: Authenticating using a Service Principal with a Client Secret

Terraform supports a number of different methods for authenticating to Azure:

I am using Authenticating to Azure using a Service Principal and a Client Secret (which is covered in this guide)

Added below configuration

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}

  client_id       = "00000000-0000-0000-0000-000000000000"
  client_secret   = "000000000000000000000000000000000000000"
  tenant_id       = "10000000-0000-0000-0000-000000000000"
  subscription_id = "20000000-0000-0000-0000-000000000000"
}

Final provider code will be

terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.105.0"
    }
  }
}

provider "azurerm" {
  features {}

  client_id       = "d1dxxxxxxxx39-4f88-9c02-362294a6cf24"
  client_secret   = "TW9xxxxxxxxxxxxxxxxxx_ht3nFvmPLM1Cc5wbds"
  tenant_id       = "8becxxxxx-55ff-478f-94e0-a96f126aa7a6"
  subscription_id = "1xxxxx-a49f-496e-91c2-0dad1860b1de"
}

To get above details please go to default directory –> App registration –> All application (or create new registration) –> you will get client Id

Tenant ID:

For client secret — go to client credentials and create it

subscription_id –> from subscription

Now add code in .tf file to create resource , here we going to create resource group

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

Run Terraform init

then , Terraform plan

Terraform validate:

Terraform apply

Terraform show

validate at azure portal

Now destroy resource group

Related Posts

Terraform Cheat Sheet: The Ultimate Reference for Infrastructure as Code (2025)

🧾 Terraform Cheat Sheet: The Ultimate Reference for Infrastructure as Code (2025) Learn and master Terraform with this complete cheat sheet β€” from basics to advanced automation….

Read More

Terraform Explained Through a Simple Story – From Manual Chaos to Automated Peace

🌍 Terraform Explained Through a Simple Story – From Manual Chaos to Automated Peace πŸšͺ Welcome to DevTown – The City of Applications Imagine a bustling city…

Read More

Terraform from Essentials to Advanced: The Complete Guide (2025)

🌍 Terraform from Essentials to Advanced: The Complete Guide (2025) Build, manage, and scale infrastructure like code – cloud-native, multi-cloud, and secure. πŸš€ What is Terraform? Terraform…

Read More

Terraform interview questions that are commonly asked in interviews

Basic Questions Intermediate Questions Advanced Questions Scenario-Based Questions Advanced and Scenario-Based Questions Mohammad Gufran Jahangir

Read More

Ultimate guide for terraform from basic to advance

What is the need of terraform IAAC? The need for Terraform Infrastructure as Code (IaAC) is driven by several key benefits: Summary: List of IaaC tools Here…

Read More

Terraform Pipeline (Part-18)

Terraform Pipeline A Terraform pipeline automates the process of planning, applying, and managing infrastructure as code (IaC) with Terraform. By integrating Terraform with a CI/CD pipeline, you…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x