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

Terraform Lab – Azure –  Local Values and Outputs

Continuation of Labs 1–4 and Part 2 (All Six Input Variable Types)Level: Beginner → Early IntermediateTerraform: 1.15.9+ within version 1.xAzureRM provider: 5.9.x (same provider constraint as Part 2)Date: 12 October 2026…

Read More

Terraform Lab – Azure – Input Variables – VMS & Netowork Demo

Continuation of Labs 1–4 · Level: Beginner · Terraform: 1.15.9 · AzureRM: 5.9.x · Updated: 12 October 2026 Objective Terraform Lab – Azure – Resources – VMS & Netowork Demo Convert the final, consolidated Lab 4 infrastructure to…

Read More

Terraform Lab – Azure – Resources – VMS & Netowork Demo

Level: Absolute BeginnerTerraform version: 1.15.9AzureRM Provider: 5.9.0Approach: Each lab builds on the previous lab. These are four complete Terraform configurations designed for students to execute sequentially. Learning Path 1. Selected Azure…

Read More

Azure: Authenticating to Azure using a Service Principal and a Client Secret

Azure Portal: Get all 4 Terraform authentication values You can do this entirely through the Azure Portal web interface. No terminal commands or Azure CLI are required….

Read More

Azure: How to Create an Azure User, Assign Permissions, and Log In

Objective Create a new user in Microsoft Azure, grant access to cloud resources, and verify that the user can log in independently without sharing your administrator credentials….

Read More

Falcosidekick on Ubuntu: Complete Installation, Configuration, Alert Forwarding, and Troubleshooting Tutorial

I read your Falco: Zero to Intermediate – Gold-Standard Hands-on Master Tutorial. It uses Ubuntu Server 24.04 LTS as its reference lab and covers Falco installation, runtime…

Read More