EduArn – Online & Offline Training with Free LMS for Python, AI, Cloud & More

Showing posts with label Azure Resource Group. Show all posts
Showing posts with label Azure Resource Group. Show all posts

Terraform Azure Resource Group Step-by-Step Guide | Complete Workflow (Init, Plan, Apply, Destroy)

 

🎯 Objective

Learn Terraform workflow by creating and managing a Resource Group in Microsoft Azure


📁 Step 1: Create Project Folder

mkdir tf-azure-rg
cd tf-azure-rg

🧾 Step 2: provider.tf

provider "azurerm" {
features {}
}

🧾 Step 3: variables.tf

variable "rg_name" {
default = "demo-rg-tf"
}

variable "location" {
default = "eastus"
}

🧾 Step 4: main.tf (Resource Group Only)

resource "azurerm_resource_group" "rg" {
name = var.rg_name
location = var.location

tags = {
environment = "Dev"
project = "Terraform-Lab"
}
}

🧪 Step 5: Terraform Workflow Execution


🔹 1. Terraform Init

terraform init

✔ Downloads Azure provider
✔ Initializes working directory


🔹 2. Terraform Validate

terraform validate

✔ Checks syntax
✔ Ensures config is correct


🔹 3. Terraform Plan

terraform plan

✔ Shows what Terraform will create

👉 Example Output:

+ azurerm_resource_group.rg will be created

🔹 4. Terraform Apply

terraform apply -auto-approve

✔ Creates Resource Group in Azure


🔹 5. Verify in Azure

Go to Azure Portal → Check Resource Group


🔹 6. Terraform Destroy

terraform destroy -auto-approve

✔ Deletes Resource Group
✔ Cleans all resources


🧠 What You Learned

✔ Write Terraform code
✔ Initialize provider
✔ Validate configuration
✔ Plan infrastructure
✔ Apply changes
✔ Destroy resources


🎯 Interview Answer (Short)

👉 Terraform workflow:
Write → Init → Validate → Plan → Apply → Destroy


💡 Bonus: Output Example

Add this in output.tf:

output "rg_name" {
value = azurerm_resource_group.rg.name
}

🚀 Next Step Suggestions

After this, try:

  • Multiple resource groups (count / for_each)
  • Modules
  • Remote backend

🎓 Learn with Eduarn

At Eduarn.com, you get:
✔ Hands-on Terraform labs
✔ Azure + DevOps real-time projects
✔ Corporate & retail training