Azure: Terraform Azure Authentication: Azure CLI

Latest Terraform Azure Authentication: Azure CLI

The recommended approach in the HashiCorp AzureRM provider’s Azure CLI authentication guide is to authenticate through Azure CLI when running Terraform locally.

With this method, you do not need ARM_CLIENT_ID, ARM_CLIENT_SECRET, or a service principal secret. You sign in using Azure CLI, and Terraform uses that authenticated identity.

Step 1 — Install Azure CLI on macOS

brew update
brew install azure-cli

If Azure CLI is already installed, check it:

az version

Step 2 — Sign in to Azure

az login

A browser window will open. Sign in with your Azure account and complete any required authentication.

Step 3 — Select your subscription

List available subscriptions:

az account list --output table

Set the subscription Terraform should manage:

az account set --subscription "<SUBSCRIPTION_ID>"

Verify:

az account show --output table

Step 4 — Configure Terraform

In your Terraform project, create or update main.tf:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 5.0"
    }
  }
}

provider "azurerm" {
  features {}
  subscription_id = "<SUBSCRIPTION_ID>"
}

resource "azurerm_resource_group" "example" {
  name     = "terraform-test-rg"
  location = "Japan East"
}

Replace <SUBSCRIPTION_ID> with your actual subscription ID. This example uses AzureRM provider version 5.x; the provider block also works with CLI authentication when using a compatible provider version.

Step 5 — Initialize and test Terraform

Run these commands from the directory containing main.tf:

terraform init
terraform validate
terraform plan

If the plan succeeds, Terraform has authenticated and can evaluate the proposed deployment. To create the resource group, run:

terraform apply

Review the plan and type yes when prompted.

Permissions: Your signed-in Azure identity must have sufficient permissions to create resource groups in the selected subscription.

Step 6 — Verify the current identity

az account show \
  --query "{Subscription:name, SubscriptionID:id, TenantID:tenantId, SignedInAs:user.name}" \
  --output table

This confirms which subscription and identity Azure CLI is using.

Official, updated documentation

Important distinction: Azure CLI authentication is ideal for local Terraform development. For unattended execution in Jenkins, GitHub Actions, or another CI/CD system, use a service principal with an appropriate credential or workload identity federation instead.

Related Posts

AWS CodeCommit – Complete Step-by-Step Tutorial

Beginner to Advanced | macOS, Linux, Git, SSH, IAM, CodeBuild This master tutorial covers the complete AWS CodeCommit workflow, from creating your first repository to managing source…

Read More

AWS Developer Services: Console Lab Guide

title AWS Developer Services: Gold-Standard Console Lab Guide subtitle CodeCommit • CodeArtifact • CodeBuild • CodeDeploy • CodePipeline author Instructor Edition | Browser-Only Labs date 10 November…

Read More

Oracle Cloud Always Free VPS — Complete Step-by-Step Tutorial

Beginner to Advanced | Updated: November 2, 2026 | Verified against official Oracle Cloud Infrastructure documentation This guide walks you through logging in to Oracle Cloud, configuring…

Read More

Microsoft Sentinel Intermediate: One Complete End-to-End Hands-On Lab – Part – 3

Module 2: Intermediate | Day 3 only | Complete instructor-and-learner manual Edition: 1 November 2026Course: Microsoft Sentinel Technical Training — 5-day progressive curriculumThis document: Day 3 only; prerequisite: successful completion of Foundations…

Read More

Microsoft Sentinel Advance: One Complete End-to-End Hands-On Lab – Part – 4

Module 3: Advanced | Day 4 only | Detection Engineering, Threat Hunting and SOAR Curriculum version: 1 November 2026Course: Five-day progressive Microsoft Sentinel technical trainingThis manual: Day 4 only — syllabus competencies A01–A14Prerequisite: Demonstrated…

Read More

Microsoft Sentinel Advance: One Complete End-to-End Hands-On Lab – Part – 5

Module 3: Advanced | Day 5 only | Enterprise Architecture, Data Lake, DevSecOps and SOC Governance Edition: 1 November 2026Training path: Day 5 of the five-day progressive Microsoft Sentinel programThis manual: Day…

Read More